Skip to content

Commit cf7fcd1

Browse files
committed
Format Python migrations
1 parent 10777f1 commit cf7fcd1

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

migrations/env.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,31 @@
1212
# Interpret the config file for Python logging.
1313
# This line sets up loggers basically.
1414
fileConfig(config.config_file_name)
15-
logger = logging.getLogger('alembic.env')
15+
logger = logging.getLogger("alembic.env")
1616

1717

1818
def get_engine():
1919
try:
2020
# this works with Flask-SQLAlchemy<3 and Alchemical
21-
return current_app.extensions['migrate'].db.get_engine()
21+
return current_app.extensions["migrate"].db.get_engine()
2222
except (TypeError, AttributeError):
2323
# this works with Flask-SQLAlchemy>=3
24-
return current_app.extensions['migrate'].db.engine
24+
return current_app.extensions["migrate"].db.engine
2525

2626

2727
def get_engine_url():
2828
try:
29-
return get_engine().url.render_as_string(hide_password=False).replace(
30-
'%', '%%')
29+
return get_engine().url.render_as_string(hide_password=False).replace("%", "%%")
3130
except AttributeError:
32-
return str(get_engine().url).replace('%', '%%')
31+
return str(get_engine().url).replace("%", "%%")
3332

3433

3534
# add your model's MetaData object here
3635
# for 'autogenerate' support
3736
# from myapp import mymodel
3837
# target_metadata = mymodel.Base.metadata
39-
config.set_main_option('sqlalchemy.url', get_engine_url())
40-
target_db = current_app.extensions['migrate'].db
38+
config.set_main_option("sqlalchemy.url", get_engine_url())
39+
target_db = current_app.extensions["migrate"].db
4140

4241
# other values from the config, defined by the needs of env.py,
4342
# can be acquired:
@@ -46,7 +45,7 @@ def get_engine_url():
4645

4746

4847
def get_metadata():
49-
if hasattr(target_db, 'metadatas'):
48+
if hasattr(target_db, "metadatas"):
5049
return target_db.metadatas[None]
5150
return target_db.metadata
5251

@@ -64,9 +63,8 @@ def run_migrations_offline():
6463
6564
"""
6665
url = config.get_main_option("sqlalchemy.url")
67-
context.configure(
68-
url=url, target_metadata=get_metadata(), literal_binds=True
69-
)
66+
context.configure(url=url, target_metadata=get_metadata(),
67+
literal_binds=True)
7068

7169
with context.begin_transaction():
7270
context.run_migrations()
@@ -84,23 +82,21 @@ def run_migrations_online():
8482
# when there are no changes to the schema
8583
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
8684
def process_revision_directives(context, revision, directives):
87-
if getattr(config.cmd_opts, 'autogenerate', False):
85+
if getattr(config.cmd_opts, "autogenerate", False):
8886
script = directives[0]
8987
if script.upgrade_ops.is_empty():
9088
directives[:] = []
91-
logger.info('No changes in schema detected.')
89+
logger.info("No changes in schema detected.")
9290

93-
conf_args = current_app.extensions['migrate'].configure_args
91+
conf_args = current_app.extensions["migrate"].configure_args
9492
if conf_args.get("process_revision_directives") is None:
9593
conf_args["process_revision_directives"] = process_revision_directives
9694

9795
connectable = get_engine()
9896

9997
with connectable.connect() as connection:
10098
context.configure(
101-
connection=connection,
102-
target_metadata=get_metadata(),
103-
**conf_args
99+
connection=connection, target_metadata=get_metadata(), **conf_args
104100
)
105101

106102
with context.begin_transaction():

migrations/versions/5d319985c5f2_create_user_table.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,36 @@
55
Create Date: 2025-01-04 19:10:25.736507
66
77
"""
8+
89
from alembic import op
910
import sqlalchemy as sa
1011

1112

1213
# revision identifiers, used by Alembic.
13-
revision = '5d319985c5f2'
14+
revision = "5d319985c5f2"
1415
down_revision = None
1516
branch_labels = None
1617
depends_on = None
1718

1819

1920
def upgrade():
2021
# ### commands auto generated by Alembic - please adjust! ###
21-
op.create_table('user',
22-
sa.Column('id', sa.Integer(), nullable=False),
23-
sa.Column('username', sa.String(length=80), nullable=False),
24-
sa.Column('xp', sa.Float(), nullable=False),
25-
sa.Column('xp_required', sa.Float(), nullable=False),
26-
sa.Column('total_xp', sa.Float(), nullable=False),
27-
sa.Column('level', sa.Integer(), nullable=False),
28-
sa.PrimaryKeyConstraint('id'),
29-
sa.UniqueConstraint('id'),
30-
sa.UniqueConstraint('username')
22+
op.create_table(
23+
"user",
24+
sa.Column("id", sa.Integer(), nullable=False),
25+
sa.Column("username", sa.String(length=80), nullable=False),
26+
sa.Column("xp", sa.Float(), nullable=False),
27+
sa.Column("xp_required", sa.Float(), nullable=False),
28+
sa.Column("total_xp", sa.Float(), nullable=False),
29+
sa.Column("level", sa.Integer(), nullable=False),
30+
sa.PrimaryKeyConstraint("id"),
31+
sa.UniqueConstraint("id"),
32+
sa.UniqueConstraint("username"),
3133
)
3234
# ### end Alembic commands ###
3335

3436

3537
def downgrade():
3638
# ### commands auto generated by Alembic - please adjust! ###
37-
op.drop_table('user')
39+
op.drop_table("user")
3840
# ### end Alembic commands ###

0 commit comments

Comments
 (0)