sass-imobiliaria/backend/migrations/versions/f030e6aef123_initial_schema_properties_property_.py

69 lines
2.8 KiB
Python

"""initial schema: properties, property_photos, homepage_config
Revision ID: f030e6aef123
Revises:
Create Date: 2026-04-13 17:39:07.705944
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f030e6aef123'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('homepage_config',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('hero_headline', sa.String(length=120), nullable=False),
sa.Column('hero_subheadline', sa.String(length=240), nullable=True),
sa.Column('hero_cta_label', sa.String(length=40), nullable=False),
sa.Column('hero_cta_url', sa.String(length=200), nullable=False),
sa.Column('featured_properties_limit', sa.Integer(), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('properties',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('title', sa.String(length=200), nullable=False),
sa.Column('slug', sa.String(length=220), nullable=False),
sa.Column('address', sa.String(length=300), nullable=True),
sa.Column('price', sa.Numeric(precision=12, scale=2), nullable=False),
sa.Column('type', sa.Enum('venda', 'aluguel', name='property_type'), nullable=False),
sa.Column('bedrooms', sa.Integer(), nullable=False),
sa.Column('bathrooms', sa.Integer(), nullable=False),
sa.Column('area_m2', sa.Integer(), nullable=False),
sa.Column('is_featured', sa.Boolean(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('properties', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_properties_slug'), ['slug'], unique=True)
op.create_table('property_photos',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('property_id', sa.UUID(), nullable=False),
sa.Column('url', sa.String(length=500), nullable=False),
sa.Column('alt_text', sa.String(length=200), nullable=False),
sa.Column('display_order', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['property_id'], ['properties.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('property_photos')
with op.batch_alter_table('properties', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_properties_slug'))
op.drop_table('properties')
op.drop_table('homepage_config')
# ### end Alembic commands ###