mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
193 lines
10 KiB
Python
193 lines
10 KiB
Python
|
"""Initial migration
|
||
|
|
||
|
Revision ID: b122c3a69fc9
|
||
|
Revises:
|
||
|
Create Date: 2022-06-22 19:54:19.153320
|
||
|
|
||
|
"""
|
||
|
import sqlalchemy as sa
|
||
|
|
||
|
from alembic import op
|
||
|
|
||
|
# revision identifiers, used by Alembic.
|
||
|
revision = 'b122c3a69fc9'
|
||
|
down_revision = None
|
||
|
branch_labels = None
|
||
|
depends_on = None
|
||
|
|
||
|
|
||
|
def upgrade() -> None:
|
||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
op.create_table('actors',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('ap_id', sa.String(), nullable=False),
|
||
|
sa.Column('ap_actor', sa.JSON(), nullable=False),
|
||
|
sa.Column('ap_type', sa.String(), nullable=False),
|
||
|
sa.Column('handle', sa.String(), nullable=True),
|
||
|
sa.PrimaryKeyConstraint('id')
|
||
|
)
|
||
|
op.create_index(op.f('ix_actors_ap_id'), 'actors', ['ap_id'], unique=True)
|
||
|
op.create_index(op.f('ix_actors_handle'), 'actors', ['handle'], unique=False)
|
||
|
op.create_index(op.f('ix_actors_id'), 'actors', ['id'], unique=False)
|
||
|
op.create_table('inbox',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('actor_id', sa.Integer(), nullable=False),
|
||
|
sa.Column('server', sa.String(), nullable=False),
|
||
|
sa.Column('is_hidden_from_stream', sa.Boolean(), nullable=False),
|
||
|
sa.Column('ap_actor_id', sa.String(), nullable=False),
|
||
|
sa.Column('ap_type', sa.String(), nullable=False),
|
||
|
sa.Column('ap_id', sa.String(), nullable=False),
|
||
|
sa.Column('ap_context', sa.String(), nullable=True),
|
||
|
sa.Column('ap_published_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('ap_object', sa.JSON(), nullable=False),
|
||
|
sa.Column('activity_object_ap_id', sa.String(), nullable=True),
|
||
|
sa.Column('visibility', sa.Enum('PUBLIC', 'UNLISTED', 'DIRECT', name='visibilityenum'), nullable=False),
|
||
|
sa.Column('relates_to_inbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('relates_to_outbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('undone_by_inbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('liked_via_outbox_object_ap_id', sa.String(), nullable=True),
|
||
|
sa.Column('announced_via_outbox_object_ap_id', sa.String(), nullable=True),
|
||
|
sa.Column('is_bookmarked', sa.Boolean(), nullable=False),
|
||
|
sa.Column('has_replies', sa.Boolean(), nullable=False),
|
||
|
sa.Column('og_meta', sa.JSON(), nullable=True),
|
||
|
sa.ForeignKeyConstraint(['actor_id'], ['actors.id'], ),
|
||
|
sa.ForeignKeyConstraint(['relates_to_inbox_object_id'], ['inbox.id'], ),
|
||
|
sa.ForeignKeyConstraint(['relates_to_outbox_object_id'], ['outbox.id'], ),
|
||
|
sa.ForeignKeyConstraint(['undone_by_inbox_object_id'], ['inbox.id'], ),
|
||
|
sa.PrimaryKeyConstraint('id')
|
||
|
)
|
||
|
op.create_index(op.f('ix_inbox_ap_id'), 'inbox', ['ap_id'], unique=True)
|
||
|
op.create_index(op.f('ix_inbox_id'), 'inbox', ['id'], unique=False)
|
||
|
op.create_table('outbox',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('is_hidden_from_homepage', sa.Boolean(), nullable=False),
|
||
|
sa.Column('public_id', sa.String(), nullable=False),
|
||
|
sa.Column('ap_type', sa.String(), nullable=False),
|
||
|
sa.Column('ap_id', sa.String(), nullable=False),
|
||
|
sa.Column('ap_context', sa.String(), nullable=True),
|
||
|
sa.Column('ap_object', sa.JSON(), nullable=False),
|
||
|
sa.Column('activity_object_ap_id', sa.String(), nullable=True),
|
||
|
sa.Column('source', sa.String(), nullable=True),
|
||
|
sa.Column('ap_published_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('visibility', sa.Enum('PUBLIC', 'UNLISTED', 'DIRECT', name='visibilityenum'), nullable=False),
|
||
|
sa.Column('likes_count', sa.Integer(), nullable=False),
|
||
|
sa.Column('announces_count', sa.Integer(), nullable=False),
|
||
|
sa.Column('replies_count', sa.Integer(), nullable=False),
|
||
|
sa.Column('webmentions', sa.JSON(), nullable=True),
|
||
|
sa.Column('og_meta', sa.JSON(), nullable=True),
|
||
|
sa.Column('is_deleted', sa.Boolean(), nullable=False),
|
||
|
sa.Column('relates_to_inbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('relates_to_outbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('undone_by_outbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.ForeignKeyConstraint(['relates_to_inbox_object_id'], ['inbox.id'], ),
|
||
|
sa.ForeignKeyConstraint(['relates_to_outbox_object_id'], ['outbox.id'], ),
|
||
|
sa.ForeignKeyConstraint(['undone_by_outbox_object_id'], ['outbox.id'], ),
|
||
|
sa.PrimaryKeyConstraint('id')
|
||
|
)
|
||
|
op.create_index(op.f('ix_outbox_ap_id'), 'outbox', ['ap_id'], unique=True)
|
||
|
op.create_index(op.f('ix_outbox_id'), 'outbox', ['id'], unique=False)
|
||
|
op.create_index(op.f('ix_outbox_public_id'), 'outbox', ['public_id'], unique=False)
|
||
|
op.create_table('followers',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('actor_id', sa.Integer(), nullable=False),
|
||
|
sa.Column('inbox_object_id', sa.Integer(), nullable=False),
|
||
|
sa.Column('ap_actor_id', sa.String(), nullable=False),
|
||
|
sa.ForeignKeyConstraint(['actor_id'], ['actors.id'], ),
|
||
|
sa.ForeignKeyConstraint(['inbox_object_id'], ['inbox.id'], ),
|
||
|
sa.PrimaryKeyConstraint('id'),
|
||
|
sa.UniqueConstraint('actor_id'),
|
||
|
sa.UniqueConstraint('ap_actor_id')
|
||
|
)
|
||
|
op.create_index(op.f('ix_followers_id'), 'followers', ['id'], unique=False)
|
||
|
op.create_table('following',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('actor_id', sa.Integer(), nullable=False),
|
||
|
sa.Column('outbox_object_id', sa.Integer(), nullable=False),
|
||
|
sa.Column('ap_actor_id', sa.String(), nullable=False),
|
||
|
sa.ForeignKeyConstraint(['actor_id'], ['actors.id'], ),
|
||
|
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
|
||
|
sa.PrimaryKeyConstraint('id'),
|
||
|
sa.UniqueConstraint('actor_id'),
|
||
|
sa.UniqueConstraint('ap_actor_id')
|
||
|
)
|
||
|
op.create_index(op.f('ix_following_id'), 'following', ['id'], unique=False)
|
||
|
op.create_table('notifications',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('notification_type', sa.Enum('NEW_FOLLOWER', 'UNFOLLOW', 'LIKE', 'UNDO_LIKE', 'ANNOUNCE', 'UNDO_ANNOUNCE', 'MENTION', name='notificationtype'), nullable=True),
|
||
|
sa.Column('is_new', sa.Boolean(), nullable=False),
|
||
|
sa.Column('actor_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('outbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('inbox_object_id', sa.Integer(), nullable=True),
|
||
|
sa.ForeignKeyConstraint(['actor_id'], ['actors.id'], ),
|
||
|
sa.ForeignKeyConstraint(['inbox_object_id'], ['inbox.id'], ),
|
||
|
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
|
||
|
sa.PrimaryKeyConstraint('id')
|
||
|
)
|
||
|
op.create_index(op.f('ix_notifications_id'), 'notifications', ['id'], unique=False)
|
||
|
op.create_table('outgoing_activities',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
sa.Column('recipient', sa.String(), nullable=False),
|
||
|
sa.Column('outbox_object_id', sa.Integer(), nullable=False),
|
||
|
sa.Column('tries', sa.Integer(), nullable=False),
|
||
|
sa.Column('next_try', sa.DateTime(timezone=True), nullable=True),
|
||
|
sa.Column('last_try', sa.DateTime(timezone=True), nullable=True),
|
||
|
sa.Column('last_status_code', sa.Integer(), nullable=True),
|
||
|
sa.Column('last_response', sa.String(), nullable=True),
|
||
|
sa.Column('is_sent', sa.Boolean(), nullable=False),
|
||
|
sa.Column('is_errored', sa.Boolean(), nullable=False),
|
||
|
sa.Column('error', sa.String(), nullable=True),
|
||
|
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
|
||
|
sa.PrimaryKeyConstraint('id')
|
||
|
)
|
||
|
op.create_index(op.f('ix_outgoing_activities_id'), 'outgoing_activities', ['id'], unique=False)
|
||
|
op.create_table('tagged_outbox_objects',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('outbox_object_id', sa.Integer(), nullable=False),
|
||
|
sa.Column('tag', sa.String(), nullable=False),
|
||
|
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
|
||
|
sa.PrimaryKeyConstraint('id'),
|
||
|
sa.UniqueConstraint('outbox_object_id', 'tag', name='uix_tagged_object')
|
||
|
)
|
||
|
op.create_index(op.f('ix_tagged_outbox_objects_id'), 'tagged_outbox_objects', ['id'], unique=False)
|
||
|
op.create_index(op.f('ix_tagged_outbox_objects_tag'), 'tagged_outbox_objects', ['tag'], unique=False)
|
||
|
# ### end Alembic commands ###
|
||
|
|
||
|
|
||
|
def downgrade() -> None:
|
||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
op.drop_index(op.f('ix_tagged_outbox_objects_tag'), table_name='tagged_outbox_objects')
|
||
|
op.drop_index(op.f('ix_tagged_outbox_objects_id'), table_name='tagged_outbox_objects')
|
||
|
op.drop_table('tagged_outbox_objects')
|
||
|
op.drop_index(op.f('ix_outgoing_activities_id'), table_name='outgoing_activities')
|
||
|
op.drop_table('outgoing_activities')
|
||
|
op.drop_index(op.f('ix_notifications_id'), table_name='notifications')
|
||
|
op.drop_table('notifications')
|
||
|
op.drop_index(op.f('ix_following_id'), table_name='following')
|
||
|
op.drop_table('following')
|
||
|
op.drop_index(op.f('ix_followers_id'), table_name='followers')
|
||
|
op.drop_table('followers')
|
||
|
op.drop_index(op.f('ix_outbox_public_id'), table_name='outbox')
|
||
|
op.drop_index(op.f('ix_outbox_id'), table_name='outbox')
|
||
|
op.drop_index(op.f('ix_outbox_ap_id'), table_name='outbox')
|
||
|
op.drop_table('outbox')
|
||
|
op.drop_index(op.f('ix_inbox_id'), table_name='inbox')
|
||
|
op.drop_index(op.f('ix_inbox_ap_id'), table_name='inbox')
|
||
|
op.drop_table('inbox')
|
||
|
op.drop_index(op.f('ix_actors_id'), table_name='actors')
|
||
|
op.drop_index(op.f('ix_actors_handle'), table_name='actors')
|
||
|
op.drop_index(op.f('ix_actors_ap_id'), table_name='actors')
|
||
|
op.drop_table('actors')
|
||
|
# ### end Alembic commands ###
|