-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Updates📢] Migrate with upgraded fields
- Loading branch information
[esekyi]
committed
Aug 25, 2024
1 parent
738d242
commit 75a0845
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
migrations/versions/4aa0dd9e6402_changed_models_id_to_uuid_from_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
"""Changed models id to UUID from sqlalchemy dialects | ||
Revision ID: 4aa0dd9e6402 | ||
Revises: | ||
Create Date: 2024-08-25 05:54:27.114460 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '4aa0dd9e6402' | ||
down_revision = None | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('category', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('name', sa.String(length=80), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('created_at', sa.DateTime(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('user', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('first_name', sa.String(length=50), nullable=False), | ||
sa.Column('last_name', sa.String(length=50), nullable=False), | ||
sa.Column('username', sa.String(length=80), nullable=False), | ||
sa.Column('email', sa.String(length=120), nullable=False), | ||
sa.Column('password_hash', sa.String(length=255), nullable=False), | ||
sa.Column('created_at', sa.DateTime(), nullable=True), | ||
sa.Column('updated_at', 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) | ||
|
||
op.create_table('recipe', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('title', sa.String(length=120), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=False), | ||
sa.Column('instructions', sa.Text(), nullable=False), | ||
sa.Column('prep_time', sa.Integer(), nullable=True), | ||
sa.Column('cook_time', sa.Integer(), nullable=True), | ||
sa.Column('servings', sa.Integer(), nullable=True), | ||
sa.Column('image_url', sa.String(length=255), nullable=True), | ||
sa.Column('category_id', sa.UUID(), nullable=False), | ||
sa.Column('user_id', sa.UUID(), nullable=False), | ||
sa.Column('created_at', sa.DateTime(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(['category_id'], ['category.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('comment', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('text', sa.Text(), nullable=False), | ||
sa.Column('user_id', sa.UUID(), nullable=False), | ||
sa.Column('recipe_id', sa.UUID(), nullable=False), | ||
sa.Column('created_at', sa.DateTime(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(['recipe_id'], ['recipe.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('ingredient', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('name', sa.String(length=120), nullable=False), | ||
sa.Column('quantity', sa.String(length=50), nullable=False), | ||
sa.Column('recipe_id', sa.UUID(), nullable=False), | ||
sa.Column('created_at', sa.DateTime(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(['recipe_id'], ['recipe.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('ingredient') | ||
op.drop_table('comment') | ||
op.drop_table('recipe') | ||
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') | ||
op.drop_table('category') | ||
# ### end Alembic commands ### |