|
|
|
@@ -0,0 +1,224 @@
|
|
|
|
|
"""phase1+2 schema
|
|
|
|
|
|
|
|
|
|
Revision ID: 92815e03f343
|
|
|
|
|
Revises:
|
|
|
|
|
Create Date: 2026-06-15 11:55:07.300934
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
from alembic import op
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
|
|
|
revision = '92815e03f343'
|
|
|
|
|
down_revision = None
|
|
|
|
|
branch_labels = None
|
|
|
|
|
depends_on = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
|
|
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
|
|
|
op.create_table('categories',
|
|
|
|
|
sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False),
|
|
|
|
|
sa.Column('slug', sa.String(length=60), nullable=False),
|
|
|
|
|
sa.Column('name', sa.String(length=80), nullable=False),
|
|
|
|
|
sa.Column('parent_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=True),
|
|
|
|
|
sa.Column('field_schema', sa.JSON(), nullable=False),
|
|
|
|
|
sa.Column('icon', sa.String(length=40), nullable=True),
|
|
|
|
|
sa.Column('sort_order', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('sponsor_id', sa.BigInteger(), nullable=True),
|
|
|
|
|
sa.Column('is_active', sa.Boolean(), nullable=False),
|
|
|
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.ForeignKeyConstraint(['parent_id'], ['categories.id'], ),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
with op.batch_alter_table('categories', schema=None) as batch_op:
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_categories_parent_id'), ['parent_id'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_categories_slug'), ['slug'], unique=True)
|
|
|
|
|
|
|
|
|
|
op.create_table('metros',
|
|
|
|
|
sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False),
|
|
|
|
|
sa.Column('slug', sa.String(length=80), nullable=False),
|
|
|
|
|
sa.Column('name', sa.String(length=120), nullable=False),
|
|
|
|
|
sa.Column('state', sa.String(length=2), nullable=True),
|
|
|
|
|
sa.Column('center_lat', sa.Float(), nullable=True),
|
|
|
|
|
sa.Column('center_lng', sa.Float(), nullable=True),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
with op.batch_alter_table('metros', schema=None) as batch_op:
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_metros_slug'), ['slug'], unique=True)
|
|
|
|
|
|
|
|
|
|
op.create_table('plans',
|
|
|
|
|
sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False),
|
|
|
|
|
sa.Column('slug', sa.String(length=40), nullable=False),
|
|
|
|
|
sa.Column('name', sa.String(length=80), nullable=False),
|
|
|
|
|
sa.Column('price_monthly_cents', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('stripe_price_id', sa.String(length=80), nullable=True),
|
|
|
|
|
sa.Column('config', sa.JSON(), nullable=False),
|
|
|
|
|
sa.Column('is_active', sa.Boolean(), nullable=False),
|
|
|
|
|
sa.Column('sort_order', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.PrimaryKeyConstraint('id'),
|
|
|
|
|
sa.UniqueConstraint('slug')
|
|
|
|
|
)
|
|
|
|
|
op.create_table('zip_geo',
|
|
|
|
|
sa.Column('zip', sa.String(length=12), nullable=False),
|
|
|
|
|
sa.Column('city', sa.String(length=80), nullable=False),
|
|
|
|
|
sa.Column('state', sa.String(length=2), nullable=False),
|
|
|
|
|
sa.Column('lat', sa.Float(), nullable=False),
|
|
|
|
|
sa.Column('lng', sa.Float(), nullable=False),
|
|
|
|
|
sa.Column('metro', sa.String(length=80), nullable=True),
|
|
|
|
|
sa.PrimaryKeyConstraint('zip')
|
|
|
|
|
)
|
|
|
|
|
with op.batch_alter_table('zip_geo', schema=None) as batch_op:
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_zip_geo_metro'), ['metro'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_zip_geo_state'), ['state'], unique=False)
|
|
|
|
|
|
|
|
|
|
op.create_table('users',
|
|
|
|
|
sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False),
|
|
|
|
|
sa.Column('email', sa.String(length=255), nullable=False),
|
|
|
|
|
sa.Column('password_hash', sa.String(length=255), nullable=False),
|
|
|
|
|
sa.Column('display_name', sa.String(length=80), nullable=False),
|
|
|
|
|
sa.Column('role', sa.Enum('free', 'subscriber', 'moderator', 'admin', name='role'), nullable=False),
|
|
|
|
|
sa.Column('status', sa.Enum('active', 'suspended', 'banned', name='userstatus'), nullable=False),
|
|
|
|
|
sa.Column('locale', sa.String(length=5), nullable=False),
|
|
|
|
|
sa.Column('tier_id', sa.BigInteger(), nullable=True),
|
|
|
|
|
sa.Column('trust_score', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('trust_tier', sa.Enum('new', 'basic', 'trusted', 'verified', name='trusttier'), nullable=False),
|
|
|
|
|
sa.Column('verified', sa.Boolean(), nullable=False),
|
|
|
|
|
sa.Column('email_verified', sa.Boolean(), nullable=False),
|
|
|
|
|
sa.Column('last_login_at', sa.DateTime(), nullable=True),
|
|
|
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.ForeignKeyConstraint(['tier_id'], ['plans.id'], ),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_users_email'), ['email'], unique=True)
|
|
|
|
|
|
|
|
|
|
op.create_table('listings',
|
|
|
|
|
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('category_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False),
|
|
|
|
|
sa.Column('title', sa.String(length=140), nullable=False),
|
|
|
|
|
sa.Column('title_norm', sa.String(length=140), nullable=False),
|
|
|
|
|
sa.Column('body', sa.Text(), nullable=False),
|
|
|
|
|
sa.Column('lang', sa.Enum('en', 'vi', 'es', name='lang'), nullable=False),
|
|
|
|
|
sa.Column('price_cents', sa.Integer(), nullable=True),
|
|
|
|
|
sa.Column('zip', sa.String(length=12), nullable=True),
|
|
|
|
|
sa.Column('city', sa.String(length=80), nullable=True),
|
|
|
|
|
sa.Column('state', sa.String(length=2), nullable=True),
|
|
|
|
|
sa.Column('lat', sa.Float(), nullable=True),
|
|
|
|
|
sa.Column('lng', sa.Float(), nullable=True),
|
|
|
|
|
sa.Column('attributes', sa.JSON(), nullable=False),
|
|
|
|
|
sa.Column('attr_condition', sa.String(length=40), nullable=True),
|
|
|
|
|
sa.Column('attr_job_type', sa.String(length=40), nullable=True),
|
|
|
|
|
sa.Column('attr_salary_min', sa.Integer(), nullable=True),
|
|
|
|
|
sa.Column('attr_salary_max', sa.Integer(), nullable=True),
|
|
|
|
|
sa.Column('status', sa.Enum('active', 'flagged', 'sold', 'expired', 'removed', name='listingstatus'), nullable=False),
|
|
|
|
|
sa.Column('is_featured', sa.Boolean(), nullable=False),
|
|
|
|
|
sa.Column('bump_at', sa.DateTime(), nullable=True),
|
|
|
|
|
sa.Column('flag_count', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('view_count', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('expires_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
|
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
with op.batch_alter_table('listings', schema=None) as batch_op:
|
|
|
|
|
batch_op.create_index('ix_listing_browse', ['status', 'expires_at'], unique=False)
|
|
|
|
|
batch_op.create_index('ix_listing_sort', ['is_featured', 'bump_at'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_attr_condition'), ['attr_condition'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_attr_job_type'), ['attr_job_type'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_attr_salary_max'), ['attr_salary_max'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_attr_salary_min'), ['attr_salary_min'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_category_id'), ['category_id'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_expires_at'), ['expires_at'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_price_cents'), ['price_cents'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_state'), ['state'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_status'), ['status'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_title_norm'), ['title_norm'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_user_id'), ['user_id'], unique=False)
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listings_zip'), ['zip'], unique=False)
|
|
|
|
|
|
|
|
|
|
op.create_table('trust_events',
|
|
|
|
|
sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False),
|
|
|
|
|
sa.Column('user_id', sa.BigInteger(), nullable=False),
|
|
|
|
|
sa.Column('type', sa.Enum('account_age', 'listing_survived', 'flag_received', 'verified_email', 'payment', name='trusteventtype'), nullable=False),
|
|
|
|
|
sa.Column('delta', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
with op.batch_alter_table('trust_events', schema=None) as batch_op:
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_trust_events_user_id'), ['user_id'], unique=False)
|
|
|
|
|
|
|
|
|
|
op.create_table('listing_images',
|
|
|
|
|
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('path', sa.String(length=255), nullable=False),
|
|
|
|
|
sa.Column('thumb_path', sa.String(length=255), nullable=True),
|
|
|
|
|
sa.Column('sort_order', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('width', sa.Integer(), nullable=True),
|
|
|
|
|
sa.Column('height', sa.Integer(), nullable=True),
|
|
|
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
|
|
|
sa.ForeignKeyConstraint(['listing_id'], ['listings.id'], ),
|
|
|
|
|
sa.PrimaryKeyConstraint('id')
|
|
|
|
|
)
|
|
|
|
|
with op.batch_alter_table('listing_images', schema=None) as batch_op:
|
|
|
|
|
batch_op.create_index(batch_op.f('ix_listing_images_listing_id'), ['listing_id'], unique=False)
|
|
|
|
|
|
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
|
|
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
|
|
|
with op.batch_alter_table('listing_images', schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listing_images_listing_id'))
|
|
|
|
|
|
|
|
|
|
op.drop_table('listing_images')
|
|
|
|
|
with op.batch_alter_table('trust_events', schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_trust_events_user_id'))
|
|
|
|
|
|
|
|
|
|
op.drop_table('trust_events')
|
|
|
|
|
with op.batch_alter_table('listings', schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_zip'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_user_id'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_title_norm'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_status'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_state'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_price_cents'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_expires_at'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_category_id'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_attr_salary_min'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_attr_salary_max'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_attr_job_type'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_listings_attr_condition'))
|
|
|
|
|
batch_op.drop_index('ix_listing_sort')
|
|
|
|
|
batch_op.drop_index('ix_listing_browse')
|
|
|
|
|
|
|
|
|
|
op.drop_table('listings')
|
|
|
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_users_email'))
|
|
|
|
|
|
|
|
|
|
op.drop_table('users')
|
|
|
|
|
with op.batch_alter_table('zip_geo', schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_zip_geo_state'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_zip_geo_metro'))
|
|
|
|
|
|
|
|
|
|
op.drop_table('zip_geo')
|
|
|
|
|
op.drop_table('plans')
|
|
|
|
|
with op.batch_alter_table('metros', schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_metros_slug'))
|
|
|
|
|
|
|
|
|
|
op.drop_table('metros')
|
|
|
|
|
with op.batch_alter_table('categories', schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_categories_slug'))
|
|
|
|
|
batch_op.drop_index(batch_op.f('ix_categories_parent_id'))
|
|
|
|
|
|
|
|
|
|
op.drop_table('categories')
|
|
|
|
|
# ### end Alembic commands ###
|