1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
"""Add email column to user table
Revision ID: 27b841f29edb
Revises:
Create Date: 2025-04-24 18:14:20.471072
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '27b841f29edb'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('toot', schema=None) as batch_op:
batch_op.alter_column('message',
existing_type=sa.VARCHAR(length=512),
type_=sa.String(length=255),
existing_nullable=False)
batch_op.alter_column('toot_time',
existing_type=sa.VARCHAR(length=8),
type_=sa.String(length=5),
existing_nullable=False)
batch_op.alter_column('day',
existing_type=sa.VARCHAR(length=10),
type_=sa.String(length=9),
existing_nullable=False)
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('email', sa.String(length=120), nullable=False))
batch_op.add_column(sa.Column('password', sa.String(length=200), nullable=False))
batch_op.alter_column('id',
existing_type=sa.VARCHAR(length=36),
type_=sa.Integer(),
existing_nullable=False,
autoincrement=True)
batch_op.alter_column('username',
existing_type=sa.VARCHAR(length=80),
type_=sa.String(length=100),
existing_nullable=False)
batch_op.create_unique_constraint(None, ['email'])
batch_op.drop_column('password_hash')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('password_hash', sa.VARCHAR(length=128), autoincrement=False, nullable=False))
batch_op.drop_constraint(None, type_='unique')
batch_op.alter_column('username',
existing_type=sa.String(length=100),
type_=sa.VARCHAR(length=80),
existing_nullable=False)
batch_op.alter_column('id',
existing_type=sa.Integer(),
type_=sa.VARCHAR(length=36),
existing_nullable=False,
autoincrement=True)
batch_op.drop_column('password')
batch_op.drop_column('email')
with op.batch_alter_table('toot', schema=None) as batch_op:
batch_op.alter_column('day',
existing_type=sa.String(length=9),
type_=sa.VARCHAR(length=10),
existing_nullable=False)
batch_op.alter_column('toot_time',
existing_type=sa.String(length=5),
type_=sa.VARCHAR(length=8),
existing_nullable=False)
batch_op.alter_column('message',
existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=512),
existing_nullable=False)
# ### end Alembic commands ###
|