Skip to content

Commit 7747f60

Browse files
committed
Format migration code
1 parent b46036e commit 7747f60

File tree

1 file changed

+61
-42
lines changed

1 file changed

+61
-42
lines changed

migrations/versions/ca738f81bbd0_add_rating_score.py

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,85 @@
55
Create Date: 2025-02-12 18:20:12.545218
66
77
"""
8+
89
from alembic import op
910
import sqlalchemy as sa
1011

1112

1213
# revision identifiers, used by Alembic.
13-
revision = 'ca738f81bbd0'
14-
down_revision = 'fc7b30bd8065'
14+
revision = "ca738f81bbd0"
15+
down_revision = "fc7b30bd8065"
1516
branch_labels = None
1617
depends_on = None
1718

1819

1920
def upgrade():
2021
# ### commands auto generated by Alembic - please adjust! ###
21-
with op.batch_alter_table('task', schema=None) as batch_op:
22-
batch_op.alter_column('streak',
23-
existing_type=sa.INTEGER(),
24-
nullable=False,
25-
existing_server_default=sa.text('0'))
26-
batch_op.alter_column('completed',
27-
existing_type=sa.INTEGER(),
28-
type_=sa.Boolean(),
29-
existing_nullable=False,
30-
existing_server_default=sa.text('0'))
22+
with op.batch_alter_table("task", schema=None) as batch_op:
23+
batch_op.alter_column(
24+
"streak",
25+
existing_type=sa.INTEGER(),
26+
nullable=False,
27+
existing_server_default=sa.text("0"),
28+
)
29+
batch_op.alter_column(
30+
"completed",
31+
existing_type=sa.INTEGER(),
32+
type_=sa.Boolean(),
33+
existing_nullable=False,
34+
existing_server_default=sa.text("0"),
35+
)
3136

32-
with op.batch_alter_table('user', schema=None) as batch_op:
33-
batch_op.add_column(sa.Column('rating', sa.Float(), server_default='0', nullable=False))
34-
batch_op.alter_column('tasks_completed',
35-
existing_type=sa.INTEGER(),
36-
nullable=False,
37-
existing_server_default=sa.text('0'))
38-
batch_op.alter_column('last_time_clicked',
39-
existing_type=sa.DATETIME(),
40-
nullable=False,
41-
existing_server_default=sa.text("'2025-01-20 00:00:00'"))
37+
with op.batch_alter_table("user", schema=None) as batch_op:
38+
batch_op.add_column(
39+
sa.Column("rating", sa.Float(), server_default="0", nullable=False)
40+
)
41+
batch_op.alter_column(
42+
"tasks_completed",
43+
existing_type=sa.INTEGER(),
44+
nullable=False,
45+
existing_server_default=sa.text("0"),
46+
)
47+
batch_op.alter_column(
48+
"last_time_clicked",
49+
existing_type=sa.DATETIME(),
50+
nullable=False,
51+
existing_server_default=sa.text("'2025-01-20 00:00:00'"),
52+
)
4253

4354
# ### end Alembic commands ###
4455

4556

4657
def downgrade():
4758
# ### commands auto generated by Alembic - please adjust! ###
48-
with op.batch_alter_table('user', schema=None) as batch_op:
49-
batch_op.alter_column('last_time_clicked',
50-
existing_type=sa.DATETIME(),
51-
nullable=True,
52-
existing_server_default=sa.text("'2025-01-20 00:00:00'"))
53-
batch_op.alter_column('tasks_completed',
54-
existing_type=sa.INTEGER(),
55-
nullable=True,
56-
existing_server_default=sa.text('0'))
57-
batch_op.drop_column('rating')
59+
with op.batch_alter_table("user", schema=None) as batch_op:
60+
batch_op.alter_column(
61+
"last_time_clicked",
62+
existing_type=sa.DATETIME(),
63+
nullable=True,
64+
existing_server_default=sa.text("'2025-01-20 00:00:00'"),
65+
)
66+
batch_op.alter_column(
67+
"tasks_completed",
68+
existing_type=sa.INTEGER(),
69+
nullable=True,
70+
existing_server_default=sa.text("0"),
71+
)
72+
batch_op.drop_column("rating")
5873

59-
with op.batch_alter_table('task', schema=None) as batch_op:
60-
batch_op.alter_column('completed',
61-
existing_type=sa.Boolean(),
62-
type_=sa.INTEGER(),
63-
existing_nullable=False,
64-
existing_server_default=sa.text('0'))
65-
batch_op.alter_column('streak',
66-
existing_type=sa.INTEGER(),
67-
nullable=True,
68-
existing_server_default=sa.text('0'))
74+
with op.batch_alter_table("task", schema=None) as batch_op:
75+
batch_op.alter_column(
76+
"completed",
77+
existing_type=sa.Boolean(),
78+
type_=sa.INTEGER(),
79+
existing_nullable=False,
80+
existing_server_default=sa.text("0"),
81+
)
82+
batch_op.alter_column(
83+
"streak",
84+
existing_type=sa.INTEGER(),
85+
nullable=True,
86+
existing_server_default=sa.text("0"),
87+
)
6988

7089
# ### end Alembic commands ###

0 commit comments

Comments
 (0)