microblog.pub/alembic/versions/2022_07_28_1725-f5717d82b3ff_initial_migration.py

394 lines
21 KiB
Python
Raw Permalink Normal View History

2022-07-28 17:28:18 +00:00
"""Initial migration
Revision ID: f5717d82b3ff
Revises:
Create Date: 2022-07-28 17:25:31.081326+00:00
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = 'f5717d82b3ff'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('actor',
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')
)
with op.batch_alter_table('actor', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_actor_ap_id'), ['ap_id'], unique=True)
batch_op.create_index(batch_op.f('ix_actor_handle'), ['handle'], unique=False)
batch_op.create_index(batch_op.f('ix_actor_id'), ['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', 'FOLLOWERS_ONLY', '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('voted_for_answers', sa.JSON(), nullable=True),
sa.Column('is_bookmarked', sa.Boolean(), nullable=False),
sa.Column('is_deleted', sa.Boolean(), nullable=False),
sa.Column('is_transient', sa.Boolean(), server_default='0', nullable=False),
sa.Column('replies_count', sa.Integer(), nullable=False),
sa.Column('og_meta', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['actor_id'], ['actor.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')
)
with op.batch_alter_table('inbox', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_inbox_activity_object_ap_id'), ['activity_object_ap_id'], unique=False)
batch_op.create_index(batch_op.f('ix_inbox_ap_id'), ['ap_id'], unique=True)
batch_op.create_index(batch_op.f('ix_inbox_ap_type'), ['ap_type'], unique=False)
batch_op.create_index(batch_op.f('ix_inbox_id'), ['id'], unique=False)
op.create_table('incoming_activity',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('webmention_source', sa.String(), nullable=True),
sa.Column('sent_by_ap_actor_id', sa.String(), nullable=True),
sa.Column('ap_id', sa.String(), nullable=True),
sa.Column('ap_object', sa.JSON(), nullable=True),
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('is_processed', sa.Boolean(), nullable=False),
sa.Column('is_errored', sa.Boolean(), nullable=False),
sa.Column('error', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('incoming_activity', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_incoming_activity_ap_id'), ['ap_id'], unique=False)
batch_op.create_index(batch_op.f('ix_incoming_activity_id'), ['id'], unique=False)
op.create_table('indieauth_authorization_request',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('code', sa.String(), nullable=False),
sa.Column('scope', sa.String(), nullable=False),
sa.Column('redirect_uri', sa.String(), nullable=False),
sa.Column('client_id', sa.String(), nullable=False),
sa.Column('code_challenge', sa.String(), nullable=True),
sa.Column('code_challenge_method', sa.String(), nullable=True),
sa.Column('is_used', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('indieauth_authorization_request', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_indieauth_authorization_request_code'), ['code'], unique=True)
batch_op.create_index(batch_op.f('ix_indieauth_authorization_request_id'), ['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('revisions', sa.JSON(), nullable=True),
sa.Column('ap_published_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('visibility', sa.Enum('PUBLIC', 'UNLISTED', 'FOLLOWERS_ONLY', '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_count', sa.Integer(), server_default='0', nullable=False),
sa.Column('og_meta', sa.JSON(), nullable=True),
sa.Column('is_pinned', sa.Boolean(), nullable=False),
sa.Column('is_transient', sa.Boolean(), server_default='0', nullable=False),
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('relates_to_actor_id', sa.Integer(), nullable=True),
sa.Column('undone_by_outbox_object_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['relates_to_actor_id'], ['actor.id'], ),
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')
)
with op.batch_alter_table('outbox', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_outbox_activity_object_ap_id'), ['activity_object_ap_id'], unique=False)
batch_op.create_index(batch_op.f('ix_outbox_ap_id'), ['ap_id'], unique=True)
batch_op.create_index(batch_op.f('ix_outbox_ap_type'), ['ap_type'], unique=False)
batch_op.create_index(batch_op.f('ix_outbox_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_outbox_public_id'), ['public_id'], unique=False)
op.create_table('upload',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('content_type', sa.String(), nullable=False),
sa.Column('content_hash', sa.String(), nullable=False),
sa.Column('has_thumbnail', sa.Boolean(), nullable=False),
sa.Column('blurhash', sa.String(), nullable=True),
sa.Column('width', sa.Integer(), nullable=True),
sa.Column('height', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('content_hash')
)
with op.batch_alter_table('upload', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_upload_id'), ['id'], unique=False)
op.create_table('follower',
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'], ['actor.id'], ),
sa.ForeignKeyConstraint(['inbox_object_id'], ['inbox.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('actor_id'),
sa.UniqueConstraint('ap_actor_id')
)
with op.batch_alter_table('follower', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_follower_id'), ['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'], ['actor.id'], ),
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('actor_id'),
sa.UniqueConstraint('ap_actor_id')
)
with op.batch_alter_table('following', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_following_id'), ['id'], unique=False)
op.create_table('indieauth_access_token',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('indieauth_authorization_request_id', sa.Integer(), nullable=True),
sa.Column('access_token', sa.String(), nullable=False),
sa.Column('expires_in', sa.Integer(), nullable=False),
sa.Column('scope', sa.String(), nullable=False),
sa.Column('is_revoked', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['indieauth_authorization_request_id'], ['indieauth_authorization_request.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('indieauth_access_token', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_indieauth_access_token_access_token'), ['access_token'], unique=True)
batch_op.create_index(batch_op.f('ix_indieauth_access_token_id'), ['id'], unique=False)
op.create_table('outbox_object_attachment',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('filename', sa.String(), nullable=False),
sa.Column('alt', sa.String(), nullable=True),
sa.Column('outbox_object_id', sa.Integer(), nullable=False),
sa.Column('upload_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
sa.ForeignKeyConstraint(['upload_id'], ['upload.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('outbox_object_attachment', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_outbox_object_attachment_id'), ['id'], unique=False)
op.create_table('outgoing_activity',
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=True),
sa.Column('inbox_object_id', sa.Integer(), nullable=True),
sa.Column('webmention_target', sa.String(), nullable=True),
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(['inbox_object_id'], ['inbox.id'], ),
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('outgoing_activity', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_outgoing_activity_id'), ['id'], unique=False)
op.create_table('poll_answer',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('outbox_object_id', sa.Integer(), nullable=False),
sa.Column('poll_type', sa.String(), nullable=False),
sa.Column('inbox_object_id', sa.Integer(), nullable=False),
sa.Column('actor_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['actor_id'], ['actor.id'], ),
sa.ForeignKeyConstraint(['inbox_object_id'], ['inbox.id'], ),
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('outbox_object_id', 'name', 'actor_id', name='uix_outbox_object_id_name_actor_id')
)
with op.batch_alter_table('poll_answer', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_poll_answer_id'), ['id'], unique=False)
batch_op.create_index('uix_one_of_outbox_object_id_actor_id', ['outbox_object_id', 'actor_id'], unique=True, sqlite_where=sa.text('poll_type = "oneOf"'))
op.create_table('tagged_outbox_object',
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')
)
with op.batch_alter_table('tagged_outbox_object', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_tagged_outbox_object_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_tagged_outbox_object_tag'), ['tag'], unique=False)
op.create_table('webmention',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('is_deleted', sa.Boolean(), nullable=False),
sa.Column('source', sa.String(), nullable=False),
sa.Column('source_microformats', sa.JSON(), nullable=True),
sa.Column('target', sa.String(), nullable=False),
sa.Column('outbox_object_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('source', 'target', name='uix_source_target')
)
with op.batch_alter_table('webmention', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_webmention_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_webmention_source'), ['source'], unique=True)
batch_op.create_index(batch_op.f('ix_webmention_target'), ['target'], 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', 'FOLLOW_REQUEST_ACCEPTED', 'FOLLOW_REQUEST_REJECTED', 'LIKE', 'UNDO_LIKE', 'ANNOUNCE', 'UNDO_ANNOUNCE', 'MENTION', 'NEW_WEBMENTION', 'UPDATED_WEBMENTION', 'DELETED_WEBMENTION', 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.Column('webmention_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['actor_id'], ['actor.id'], ),
sa.ForeignKeyConstraint(['inbox_object_id'], ['inbox.id'], ),
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
sa.ForeignKeyConstraint(['webmention_id'], ['webmention.id'], name='fk_webmention_id'),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('notifications', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_notifications_id'), ['id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('notifications', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_notifications_id'))
op.drop_table('notifications')
with op.batch_alter_table('webmention', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_webmention_target'))
batch_op.drop_index(batch_op.f('ix_webmention_source'))
batch_op.drop_index(batch_op.f('ix_webmention_id'))
op.drop_table('webmention')
with op.batch_alter_table('tagged_outbox_object', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_tagged_outbox_object_tag'))
batch_op.drop_index(batch_op.f('ix_tagged_outbox_object_id'))
op.drop_table('tagged_outbox_object')
with op.batch_alter_table('poll_answer', schema=None) as batch_op:
batch_op.drop_index('uix_one_of_outbox_object_id_actor_id', sqlite_where=sa.text('poll_type = "oneOf"'))
batch_op.drop_index(batch_op.f('ix_poll_answer_id'))
op.drop_table('poll_answer')
with op.batch_alter_table('outgoing_activity', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_outgoing_activity_id'))
op.drop_table('outgoing_activity')
with op.batch_alter_table('outbox_object_attachment', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_outbox_object_attachment_id'))
op.drop_table('outbox_object_attachment')
with op.batch_alter_table('indieauth_access_token', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_indieauth_access_token_id'))
batch_op.drop_index(batch_op.f('ix_indieauth_access_token_access_token'))
op.drop_table('indieauth_access_token')
with op.batch_alter_table('following', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_following_id'))
op.drop_table('following')
with op.batch_alter_table('follower', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_follower_id'))
op.drop_table('follower')
with op.batch_alter_table('upload', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_upload_id'))
op.drop_table('upload')
with op.batch_alter_table('outbox', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_outbox_public_id'))
batch_op.drop_index(batch_op.f('ix_outbox_id'))
batch_op.drop_index(batch_op.f('ix_outbox_ap_type'))
batch_op.drop_index(batch_op.f('ix_outbox_ap_id'))
batch_op.drop_index(batch_op.f('ix_outbox_activity_object_ap_id'))
op.drop_table('outbox')
with op.batch_alter_table('indieauth_authorization_request', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_indieauth_authorization_request_id'))
batch_op.drop_index(batch_op.f('ix_indieauth_authorization_request_code'))
op.drop_table('indieauth_authorization_request')
with op.batch_alter_table('incoming_activity', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_incoming_activity_id'))
batch_op.drop_index(batch_op.f('ix_incoming_activity_ap_id'))
op.drop_table('incoming_activity')
with op.batch_alter_table('inbox', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_inbox_id'))
batch_op.drop_index(batch_op.f('ix_inbox_ap_type'))
batch_op.drop_index(batch_op.f('ix_inbox_ap_id'))
batch_op.drop_index(batch_op.f('ix_inbox_activity_object_ap_id'))
op.drop_table('inbox')
with op.batch_alter_table('actor', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_actor_id'))
batch_op.drop_index(batch_op.f('ix_actor_handle'))
batch_op.drop_index(batch_op.f('ix_actor_ap_id'))
op.drop_table('actor')
# ### end Alembic commands ###