Initial commit for new v2

This commit is contained in:
Thomas Sileo 2022-06-22 20:11:22 +02:00
commit d528369954
63 changed files with 7961 additions and 0 deletions

1
alembic/README Normal file
View file

@ -0,0 +1 @@
Generic single-database configuration.

81
alembic/env.py Normal file
View file

@ -0,0 +1,81 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
import app.models # noqa: F401 # Register models
from alembic import context
from app.database import SQLALCHEMY_DATABASE_URL
from app.database import Base
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

24
alembic/script.py.mako Normal file
View file

@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}

View file

@ -0,0 +1,192 @@
"""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 ###