diff --git a/migrations/versions/247c26a69e33_add_favorites_table.py b/migrations/versions/247c26a69e33_add_favorites_table.py new file mode 100644 index 0000000..608537e --- /dev/null +++ b/migrations/versions/247c26a69e33_add_favorites_table.py @@ -0,0 +1,89 @@ +"""add favorites table + +Revision ID: 247c26a69e33 +Revises: 92815e03f343 +Create Date: 2026-06-15 16:53:53.086035 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '247c26a69e33' +down_revision = '92815e03f343' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('conversations', + sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False), + sa.Column('listing_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), + sa.Column('buyer_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), + sa.Column('seller_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), + sa.Column('last_message_at', sa.DateTime(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['buyer_id'], ['users.id'], ), + sa.ForeignKeyConstraint(['listing_id'], ['listings.id'], ), + sa.ForeignKeyConstraint(['seller_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('listing_id', 'buyer_id', name='uq_conv_listing_buyer') + ) + with op.batch_alter_table('conversations', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_conversations_buyer_id'), ['buyer_id'], unique=False) + batch_op.create_index(batch_op.f('ix_conversations_last_message_at'), ['last_message_at'], unique=False) + batch_op.create_index(batch_op.f('ix_conversations_listing_id'), ['listing_id'], unique=False) + batch_op.create_index(batch_op.f('ix_conversations_seller_id'), ['seller_id'], unique=False) + + op.create_table('favorites', + sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False), + sa.Column('user_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), + sa.Column('listing_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['listing_id'], ['listings.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('user_id', 'listing_id', name='uq_fav_user_listing') + ) + with op.batch_alter_table('favorites', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_favorites_listing_id'), ['listing_id'], unique=False) + batch_op.create_index(batch_op.f('ix_favorites_user_id'), ['user_id'], unique=False) + + op.create_table('messages', + sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False), + sa.Column('conversation_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), + sa.Column('sender_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), + sa.Column('body', sa.Text(), nullable=False), + sa.Column('read_at', sa.DateTime(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ), + sa.ForeignKeyConstraint(['sender_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('messages', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_messages_conversation_id'), ['conversation_id'], unique=False) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('messages', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_messages_conversation_id')) + + op.drop_table('messages') + with op.batch_alter_table('favorites', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_favorites_user_id')) + batch_op.drop_index(batch_op.f('ix_favorites_listing_id')) + + op.drop_table('favorites') + with op.batch_alter_table('conversations', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_conversations_seller_id')) + batch_op.drop_index(batch_op.f('ix_conversations_listing_id')) + batch_op.drop_index(batch_op.f('ix_conversations_last_message_at')) + batch_op.drop_index(batch_op.f('ix_conversations_buyer_id')) + + op.drop_table('conversations') + # ### end Alembic commands ### diff --git a/migrations/versions/f2d6b231e3e4_phase_3_5_schema_messaging_favorites_.py b/migrations/versions/f2d6b231e3e4_phase_3_5_schema_messaging_favorites_.py index f8649b3..94b0fcf 100644 --- a/migrations/versions/f2d6b231e3e4_phase_3_5_schema_messaging_favorites_.py +++ b/migrations/versions/f2d6b231e3e4_phase_3_5_schema_messaging_favorites_.py @@ -1,7 +1,7 @@ -"""phase 3-5 schema: messaging, favorites, billing, ads +"""phase 3-5 schema: billing, ads Revision ID: f2d6b231e3e4 -Revises: 92815e03f343 +Revises: 247c26a69e33 Create Date: 2026-06-16 10:54:41.003239 """ @@ -11,7 +11,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. revision = 'f2d6b231e3e4' -down_revision = '92815e03f343' +down_revision = '247c26a69e33' branch_labels = None depends_on = None @@ -109,39 +109,6 @@ def upgrade(): batch_op.create_index(batch_op.f('ix_boosts_expires_at'), ['expires_at'], unique=False) batch_op.create_index(batch_op.f('ix_boosts_listing_id'), ['listing_id'], unique=False) - op.create_table('conversations', - sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False), - sa.Column('listing_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), - sa.Column('buyer_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), - sa.Column('seller_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), - sa.Column('last_message_at', sa.DateTime(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(['buyer_id'], ['users.id'], ), - sa.ForeignKeyConstraint(['listing_id'], ['listings.id'], ), - sa.ForeignKeyConstraint(['seller_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('listing_id', 'buyer_id', name='uq_conv_listing_buyer') - ) - with op.batch_alter_table('conversations', schema=None) as batch_op: - batch_op.create_index(batch_op.f('ix_conversations_buyer_id'), ['buyer_id'], unique=False) - batch_op.create_index(batch_op.f('ix_conversations_last_message_at'), ['last_message_at'], unique=False) - batch_op.create_index(batch_op.f('ix_conversations_listing_id'), ['listing_id'], unique=False) - batch_op.create_index(batch_op.f('ix_conversations_seller_id'), ['seller_id'], unique=False) - - op.create_table('favorites', - sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False), - sa.Column('user_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), - sa.Column('listing_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(['listing_id'], ['listings.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('user_id', 'listing_id', name='uq_fav_user_listing') - ) - with op.batch_alter_table('favorites', schema=None) as batch_op: - batch_op.create_index(batch_op.f('ix_favorites_listing_id'), ['listing_id'], unique=False) - batch_op.create_index(batch_op.f('ix_favorites_user_id'), ['user_id'], unique=False) - op.create_table('promoted_keywords', sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False), sa.Column('keyword', sa.String(length=80), nullable=False), @@ -157,46 +124,16 @@ def upgrade(): batch_op.create_index(batch_op.f('ix_promoted_keywords_expires_at'), ['expires_at'], unique=False) batch_op.create_index(batch_op.f('ix_promoted_keywords_keyword'), ['keyword'], unique=False) - op.create_table('messages', - sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False), - sa.Column('conversation_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), - sa.Column('sender_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False), - sa.Column('body', sa.Text(), nullable=False), - sa.Column('read_at', sa.DateTime(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=False), - sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ), - sa.ForeignKeyConstraint(['sender_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') - ) - with op.batch_alter_table('messages', schema=None) as batch_op: - batch_op.create_index(batch_op.f('ix_messages_conversation_id'), ['conversation_id'], unique=False) - # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('messages', schema=None) as batch_op: - batch_op.drop_index(batch_op.f('ix_messages_conversation_id')) - - op.drop_table('messages') with op.batch_alter_table('promoted_keywords', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_promoted_keywords_keyword')) batch_op.drop_index(batch_op.f('ix_promoted_keywords_expires_at')) op.drop_table('promoted_keywords') - with op.batch_alter_table('favorites', schema=None) as batch_op: - batch_op.drop_index(batch_op.f('ix_favorites_user_id')) - batch_op.drop_index(batch_op.f('ix_favorites_listing_id')) - - op.drop_table('favorites') - with op.batch_alter_table('conversations', schema=None) as batch_op: - batch_op.drop_index(batch_op.f('ix_conversations_seller_id')) - batch_op.drop_index(batch_op.f('ix_conversations_listing_id')) - batch_op.drop_index(batch_op.f('ix_conversations_last_message_at')) - batch_op.drop_index(batch_op.f('ix_conversations_buyer_id')) - - op.drop_table('conversations') with op.batch_alter_table('boosts', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_boosts_listing_id')) batch_op.drop_index(batch_op.f('ix_boosts_expires_at'))