site/backend/migrations/versions/4a2c3a72038e_.py

62 lines
2.2 KiB
Python
Raw Normal View History

2024-08-03 11:59:05 +00:00
"""empty message
2024-08-01 13:35:28 +00:00
2024-08-03 12:34:12 +00:00
Revision ID: 4a2c3a72038e
2024-08-03 11:59:05 +00:00
Revises:
2024-08-03 12:34:12 +00:00
Create Date: 2024-08-03 05:02:15.935738
2024-08-01 13:35:28 +00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
2024-08-03 12:34:12 +00:00
revision = '4a2c3a72038e'
2024-08-03 11:59:05 +00:00
down_revision = None
2024-08-01 13:35:28 +00:00
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
2024-08-03 11:59:05 +00:00
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=64), nullable=False),
sa.Column('email', sa.String(length=120), nullable=False),
sa.Column('password_hash', sa.String(length=256), nullable=True),
sa.Column('about_me', sa.String(length=140), nullable=True),
sa.Column('last_seen', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_user_email'), ['email'], unique=True)
batch_op.create_index(batch_op.f('ix_user_username'), ['username'], unique=True)
2024-08-01 13:35:28 +00:00
op.create_table('post',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('body', sa.String(length=140), nullable=False),
sa.Column('timestamp', sa.DateTime(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('post', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_post_timestamp'), ['timestamp'], unique=False)
batch_op.create_index(batch_op.f('ix_post_user_id'), ['user_id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('post', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_post_user_id'))
batch_op.drop_index(batch_op.f('ix_post_timestamp'))
op.drop_table('post')
2024-08-03 11:59:05 +00:00
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_user_username'))
batch_op.drop_index(batch_op.f('ix_user_email'))
op.drop_table('user')
2024-08-01 13:35:28 +00:00
# ### end Alembic commands ###