"""initial tables Revision ID: 54f1dd40e066 Revises: Create Date: 2023-08-04 21:27:35.452094 """ import sqlalchemy_utils from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '54f1dd40e066' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('banned_instances', sa.Column('id', sa.Integer(), nullable=False), sa.Column('domain', sa.String(length=256), nullable=True), sa.Column('reason', sa.String(length=256), nullable=True), sa.Column('initiator', sa.String(length=256), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('domain', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=True), sa.Column('post_count', sa.Integer(), nullable=True), sa.Column('banned', sa.Boolean(), nullable=True), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('domain', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_domain_banned'), ['banned'], unique=False) batch_op.create_index(batch_op.f('ix_domain_name'), ['name'], unique=False) op.create_table('file', sa.Column('id', sa.Integer(), nullable=False), sa.Column('file_path', sa.String(length=255), nullable=True), sa.Column('file_name', sa.String(length=255), nullable=True), sa.Column('width', sa.Integer(), nullable=True), sa.Column('height', sa.Integer(), nullable=True), sa.Column('alt_text', sa.String(length=256), nullable=True), sa.Column('source_url', sa.String(length=256), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('settings', sa.Column('name', sa.String(length=50), nullable=False), sa.Column('value', sa.String(length=1024), nullable=True), sa.PrimaryKeyConstraint('name') ) op.create_table('community', sa.Column('id', sa.Integer(), nullable=False), sa.Column('icon_id', sa.Integer(), nullable=True), sa.Column('name', sa.String(length=256), nullable=True), sa.Column('title', sa.String(length=256), nullable=True), sa.Column('description', sa.Text(), nullable=True), sa.Column('rules', sa.Text(), nullable=True), sa.Column('subscriptions_count', sa.Integer(), nullable=True), sa.Column('post_count', sa.Integer(), nullable=True), sa.Column('post_reply_count', sa.Integer(), nullable=True), sa.Column('nsfw', sa.Boolean(), nullable=True), sa.Column('nsfl', sa.Boolean(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('last_active', sa.DateTime(), nullable=True), sa.Column('public_key', sa.Text(), nullable=True), sa.Column('private_key', sa.Text(), nullable=True), sa.Column('ap_id', sa.String(length=255), nullable=True), sa.Column('ap_profile_id', sa.String(length=255), nullable=True), sa.Column('ap_followers_url', sa.String(length=255), nullable=True), sa.Column('ap_preferred_username', sa.String(length=255), nullable=True), sa.Column('ap_discoverable', sa.Boolean(), nullable=True), sa.Column('ap_public_url', sa.String(length=255), nullable=True), sa.Column('ap_fetched_at', sa.DateTime(), nullable=True), sa.Column('ap_deleted_at', sa.DateTime(), nullable=True), sa.Column('ap_inbox_url', sa.String(length=255), nullable=True), sa.Column('ap_domain', sa.String(length=255), nullable=True), sa.Column('banned', sa.Boolean(), nullable=True), sa.Column('searchable', sa.Boolean(), nullable=True), sa.Column('search_vector', sqlalchemy_utils.types.ts_vector.TSVectorType(), nullable=True), sa.ForeignKeyConstraint(['icon_id'], ['file.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_name', sa.String(length=255), nullable=True), sa.Column('email', sa.String(length=255), nullable=True), sa.Column('password_hash', sa.String(length=128), nullable=True), sa.Column('verified', sa.Boolean(), nullable=True), sa.Column('banned', sa.Boolean(), nullable=True), sa.Column('about', sa.Text(), nullable=True), sa.Column('keywords', sa.String(length=256), nullable=True), sa.Column('show_nsfw', sa.Boolean(), nullable=True), sa.Column('show_nsfl', sa.Boolean(), nullable=True), sa.Column('created', sa.DateTime(), nullable=True), sa.Column('last_seen', sa.DateTime(), nullable=True), sa.Column('role', sa.Integer(), nullable=True), sa.Column('avatar_id', sa.Integer(), nullable=True), sa.Column('cover_id', sa.Integer(), nullable=True), sa.Column('public_key', sa.Text(), nullable=True), sa.Column('private_key', sa.Text(), nullable=True), sa.Column('newsletter', sa.Boolean(), nullable=True), sa.Column('bounces', sa.SmallInteger(), nullable=True), sa.Column('timezone', sa.String(length=20), nullable=True), sa.Column('stripe_customer_id', sa.String(length=50), nullable=True), sa.Column('stripe_subscription_id', sa.String(length=50), nullable=True), sa.Column('searchable', sa.Boolean(), nullable=True), sa.Column('ap_id', sa.String(length=255), nullable=True), sa.Column('ap_profile_id', sa.String(length=255), nullable=True), sa.Column('ap_public_url', sa.String(length=255), nullable=True), sa.Column('ap_fetched_at', sa.DateTime(), nullable=True), sa.Column('ap_followers_url', sa.String(length=255), nullable=True), sa.Column('ap_preferred_username', sa.String(length=255), nullable=True), sa.Column('ap_manually_approves_followers', sa.Boolean(), nullable=True), sa.Column('ap_deleted_at', sa.DateTime(), nullable=True), sa.Column('ap_inbox_url', sa.String(length=255), nullable=True), sa.Column('ap_domain', sa.String(length=255), nullable=True), sa.Column('search_vector', sqlalchemy_utils.types.ts_vector.TSVectorType(), nullable=True), sa.ForeignKeyConstraint(['avatar_id'], ['file.id'], ), sa.ForeignKeyConstraint(['cover_id'], ['file.id'], ), 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=False) batch_op.create_index(batch_op.f('ix_user_user_name'), ['user_name'], unique=True) op.create_table('activity_log', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('activity_type', sa.String(length=64), nullable=True), sa.Column('activity', sa.String(length=255), nullable=True), sa.Column('timestamp', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('activity_log', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_activity_log_timestamp'), ['timestamp'], unique=False) batch_op.create_index(batch_op.f('ix_activity_log_user_id'), ['user_id'], unique=False) op.create_table('community_block', sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('community_id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['community_id'], ['community.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('user_id', 'community_id') ) op.create_table('community_member', sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('community_id', sa.Integer(), nullable=False), sa.Column('is_moderator', sa.Boolean(), nullable=True), sa.Column('is_owner', sa.Boolean(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['community_id'], ['community.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('user_id', 'community_id') ) op.create_table('domain_block', sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('domain_id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('user_id', 'domain_id') ) op.create_table('post', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('community_id', sa.Integer(), nullable=True), sa.Column('image_id', sa.Integer(), nullable=True), sa.Column('domain_id', sa.Integer(), nullable=True), sa.Column('slug', sa.String(length=255), nullable=True), sa.Column('title', sa.String(length=255), nullable=True), sa.Column('url', sa.String(length=2048), nullable=True), sa.Column('body', sa.Text(), nullable=True), sa.Column('type', sa.Integer(), nullable=True), sa.Column('has_embed', sa.Boolean(), nullable=True), sa.Column('reply_count', sa.Integer(), nullable=True), sa.Column('score', sa.Integer(), nullable=True), sa.Column('nsfw', sa.Boolean(), nullable=True), sa.Column('nsfl', sa.Boolean(), nullable=True), sa.Column('sticky', sa.Boolean(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('posted_at', sa.DateTime(), nullable=True), sa.Column('last_active', sa.DateTime(), nullable=True), sa.Column('ip', sa.String(length=50), nullable=True), sa.Column('up_votes', sa.Integer(), nullable=True), sa.Column('down_votes', sa.Integer(), nullable=True), sa.Column('ranking', sa.Integer(), nullable=True), sa.Column('language', sa.String(length=10), nullable=True), sa.Column('edited_at', sa.DateTime(), nullable=True), sa.Column('ap_id', sa.String(length=255), nullable=True), sa.Column('search_vector', sqlalchemy_utils.types.ts_vector.TSVectorType(), nullable=True), sa.ForeignKeyConstraint(['community_id'], ['community.id'], ), sa.ForeignKeyConstraint(['domain_id'], ['domain.id'], ), sa.ForeignKeyConstraint(['image_id'], ['file.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('post', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_post_community_id'), ['community_id'], unique=False) batch_op.create_index(batch_op.f('ix_post_created_at'), ['created_at'], unique=False) batch_op.create_index(batch_op.f('ix_post_domain_id'), ['domain_id'], unique=False) batch_op.create_index(batch_op.f('ix_post_image_id'), ['image_id'], unique=False) batch_op.create_index(batch_op.f('ix_post_last_active'), ['last_active'], unique=False) batch_op.create_index(batch_op.f('ix_post_posted_at'), ['posted_at'], unique=False) batch_op.create_index(batch_op.f('ix_post_score'), ['score'], unique=False) batch_op.create_index(batch_op.f('ix_post_user_id'), ['user_id'], unique=False) op.create_table('user_block', sa.Column('id', sa.Integer(), nullable=False), sa.Column('blocker_id', sa.Integer(), nullable=True), sa.Column('blocked_id', sa.Integer(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['blocked_id'], ['user.id'], ), sa.ForeignKeyConstraint(['blocker_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('user_note', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('target_id', sa.Integer(), nullable=True), sa.Column('body', sa.Text(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['target_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('post_reply', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('post_id', sa.Integer(), nullable=True), sa.Column('community_id', sa.Integer(), nullable=True), sa.Column('image_id', sa.Integer(), nullable=True), sa.Column('parent_id', sa.Integer(), nullable=True), sa.Column('root_id', sa.Integer(), nullable=True), sa.Column('body', sa.Text(), nullable=True), sa.Column('score', sa.Integer(), nullable=True), sa.Column('nsfw', sa.Boolean(), nullable=True), sa.Column('nsfl', sa.Boolean(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('posted_at', sa.DateTime(), nullable=True), sa.Column('ip', sa.String(length=50), nullable=True), sa.Column('up_votes', sa.Integer(), nullable=True), sa.Column('down_votes', sa.Integer(), nullable=True), sa.Column('ranking', sa.Integer(), nullable=True), sa.Column('language', sa.String(length=10), nullable=True), sa.Column('edited_at', sa.DateTime(), nullable=True), sa.Column('ap_id', sa.String(length=255), nullable=True), sa.Column('search_vector', sqlalchemy_utils.types.ts_vector.TSVectorType(), nullable=True), sa.ForeignKeyConstraint(['community_id'], ['community.id'], ), sa.ForeignKeyConstraint(['image_id'], ['file.id'], ), sa.ForeignKeyConstraint(['post_id'], ['post.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('post_reply', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_post_reply_community_id'), ['community_id'], unique=False) batch_op.create_index(batch_op.f('ix_post_reply_created_at'), ['created_at'], unique=False) batch_op.create_index(batch_op.f('ix_post_reply_image_id'), ['image_id'], unique=False) batch_op.create_index(batch_op.f('ix_post_reply_post_id'), ['post_id'], unique=False) batch_op.create_index(batch_op.f('ix_post_reply_posted_at'), ['posted_at'], unique=False) batch_op.create_index(batch_op.f('ix_post_reply_score'), ['score'], unique=False) batch_op.create_index(batch_op.f('ix_post_reply_user_id'), ['user_id'], unique=False) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('post_reply', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_post_reply_user_id')) batch_op.drop_index(batch_op.f('ix_post_reply_score')) batch_op.drop_index(batch_op.f('ix_post_reply_posted_at')) batch_op.drop_index(batch_op.f('ix_post_reply_post_id')) batch_op.drop_index(batch_op.f('ix_post_reply_image_id')) batch_op.drop_index(batch_op.f('ix_post_reply_created_at')) batch_op.drop_index(batch_op.f('ix_post_reply_community_id')) op.drop_table('post_reply') op.drop_table('user_note') op.drop_table('user_block') with op.batch_alter_table('post', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_post_user_id')) batch_op.drop_index(batch_op.f('ix_post_score')) batch_op.drop_index(batch_op.f('ix_post_posted_at')) batch_op.drop_index(batch_op.f('ix_post_last_active')) batch_op.drop_index(batch_op.f('ix_post_image_id')) batch_op.drop_index(batch_op.f('ix_post_domain_id')) batch_op.drop_index(batch_op.f('ix_post_created_at')) batch_op.drop_index(batch_op.f('ix_post_community_id')) op.drop_table('post') op.drop_table('domain_block') op.drop_table('community_member') op.drop_table('community_block') with op.batch_alter_table('activity_log', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_activity_log_user_id')) batch_op.drop_index(batch_op.f('ix_activity_log_timestamp')) op.drop_table('activity_log') with op.batch_alter_table('user', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_user_user_name')) batch_op.drop_index(batch_op.f('ix_user_email')) op.drop_table('user') op.drop_table('community') op.drop_table('settings') op.drop_table('file') with op.batch_alter_table('domain', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_domain_name')) batch_op.drop_index(batch_op.f('ix_domain_banned')) op.drop_table('domain') op.drop_table('banned_instances') # ### end Alembic commands ###