Skip to content

Commit

Permalink
Merge pull request #403 from atlas-bi/alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherpickering authored Jun 13, 2023
2 parents 01943db + 8ccdcc1 commit 700f78c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.10.0
2.10.1-alpha.1
7 changes: 6 additions & 1 deletion migrations/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
keys = root,sqlalchemy,alembic,flask_migrate

[handlers]
keys = console
Expand All @@ -33,6 +33,11 @@ level = INFO
handlers =
qualname = alembic

[logger_flask_migrate]
level = INFO
handlers =
qualname = flask_migrate

[handler_console]
class = StreamHandler
args = (sys.stderr,)
Expand Down
39 changes: 26 additions & 13 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -21,17 +20,35 @@
# target_metadata = mymodel.Base.metadata
from flask import current_app

config.set_main_option(
"sqlalchemy.url",
str(current_app.extensions["migrate"].db.engine.url).replace("%", "%%"),
)
target_metadata = current_app.extensions["migrate"].db.metadata

def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
except TypeError:
# this works with Flask-SQLAlchemy>=3
return current_app.extensions['migrate'].db.engine


def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
except AttributeError:
return str(get_engine().url).replace('%', '%%')

config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.

def get_metadata():
if hasattr(target_db, 'metadatas'):
return target_db.metadatas[None]
return target_db.metadata

def run_migrations_offline():
"""Run migrations in 'offline' mode.
Expand All @@ -46,7 +63,7 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
context.configure(url=url, target_metadata=get_metadata(), literal_binds=True)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -70,16 +87,12 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info("No changes in schema detected.")

connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
connectable = get_engine()

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
target_metadata=get_metadata(),
process_revision_directives=process_revision_directives,
**current_app.extensions["migrate"].configure_args
)
Expand Down
6 changes: 0 additions & 6 deletions migrations/versions/0fe33867bdbf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('connection_database', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_connection_database_connection_id'), ['connection_id'], unique=False)

with op.batch_alter_table('login', schema=None) as batch_op:
batch_op.alter_column('login_date',
existing_type=postgresql.TIMESTAMP(timezone=True),
Expand Down Expand Up @@ -92,7 +89,4 @@ def downgrade():
existing_nullable=True,
existing_server_default=sa.text('now()'))

with op.batch_alter_table('connection_database', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_connection_database_connection_id'))

# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@
"test:lint": "poetry run tox -e lint",
"test:prettier": "prettier --check --config .prettierrc \"web/**/*.{ts,css,less,scss,js,json,md,yaml,html}\""
},
"version": "2.10.0"
"version": "2.10.1-alpha.1"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ packages = [
]
readme = "readme.md"
repository = "https://github.com/atlas-bi/Hub"
version = "2.10.0"
version = "2.10.1-alpha.1"

[tool.poetry.dependencies]
Flask = "^2.0.1"
Expand Down

0 comments on commit 700f78c

Please sign in to comment.