From 75a0845dbfc29e9cdee8dba0a6367629b74909b9 Mon Sep 17 00:00:00 2001 From: "[esekyi]" <[sskert10@gmail.com]> Date: Sun, 25 Aug 2024 22:55:01 +0000 Subject: [PATCH] =?UTF-8?q?[Updates=F0=9F=93=A2]=20Migrate=20with=20upgrad?= =?UTF-8?q?ed=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...d9e6402_changed_models_id_to_uuid_from_.py | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 migrations/versions/4aa0dd9e6402_changed_models_id_to_uuid_from_.py diff --git a/migrations/versions/4aa0dd9e6402_changed_models_id_to_uuid_from_.py b/migrations/versions/4aa0dd9e6402_changed_models_id_to_uuid_from_.py new file mode 100644 index 0000000..1af4321 --- /dev/null +++ b/migrations/versions/4aa0dd9e6402_changed_models_id_to_uuid_from_.py @@ -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 ###