This commit is contained in:
2021-11-14 10:38:47 +03:00
commit 30835e31fa
43 changed files with 2366 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,66 @@
from logging.config import fileConfig
from alembic import context
import sys, os
from sqlalchemy.engine import create_engine
from core.db import DATABASE_URL
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../../')
config = context.config
from app.models import BaseMeta
target_metadata = BaseMeta.metadata
def run_migrations_offline():
"""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():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = create_engine(DATABASE_URL)
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()

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():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,30 @@
"""empty message
Revision ID: 6d0dbf1e4998
Revises: 9c4b98440632
Create Date: 2021-11-07 20:23:39.656518
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '6d0dbf1e4998'
down_revision = '9c4b98440632'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint('uc_sequence_infos_sequence_position', 'sequence_infos', ['sequence', 'position'])
op.create_unique_constraint('uc_translations_book_position', 'translations', ['book', 'position'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('uc_translations_book_position', 'translations', type_='unique')
op.drop_constraint('uc_sequence_infos_sequence_position', 'sequence_infos', type_='unique')
# ### end Alembic commands ###

View File

@@ -0,0 +1,35 @@
"""empty message
Revision ID: 9c4b98440632
Revises: d172032adeaf
Create Date: 2021-11-07 16:21:08.210333
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '9c4b98440632'
down_revision = 'd172032adeaf'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('books_authors',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('author', sa.Integer(), nullable=True),
sa.Column('book', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['author'], ['authors.id'], name='fk_books_authors_authors_author_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_books_authors_books_book_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('books_authors')
# ### end Alembic commands ###

View File

@@ -0,0 +1,112 @@
"""empty message
Revision ID: d172032adeaf
Revises:
Create Date: 2021-11-05 17:22:11.717389
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd172032adeaf'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('sources',
sa.Column('id', sa.SmallInteger(), nullable=False),
sa.Column('name', sa.String(length=32), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('authors',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('source', sa.SmallInteger(), nullable=False),
sa.Column('remote_id', sa.Integer(), nullable=False),
sa.Column('first_name', sa.String(length=256), nullable=False),
sa.Column('last_name', sa.String(length=256), nullable=False),
sa.Column('middle_name', sa.String(length=256), nullable=True),
sa.ForeignKeyConstraint(['source'], ['sources.id'], name='fk_authors_sources_id_source'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('source', 'remote_id', name='uc_authors_source_remote_id')
)
op.create_table('books',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('source', sa.SmallInteger(), nullable=False),
sa.Column('remote_id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=256), nullable=False),
sa.Column('lang', sa.String(length=2), nullable=False),
sa.Column('file_type', sa.String(length=4), nullable=False),
sa.Column('uploaded', sa.Date(), nullable=False),
sa.ForeignKeyConstraint(['source'], ['sources.id'], name='fk_books_sources_id_source'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('source', 'remote_id', name='uc_books_source_remote_id')
)
op.create_table('sequences',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('source', sa.SmallInteger(), nullable=False),
sa.Column('remote_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=256), nullable=False),
sa.ForeignKeyConstraint(['source'], ['sources.id'], name='fk_sequences_sources_id_source'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('source', 'remote_id', name='uc_sequences_source_remote_id')
)
op.create_table('author_annotations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('author', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=256), nullable=False),
sa.Column('text', sa.Text(), nullable=False),
sa.Column('file', sa.String(length=256), nullable=True),
sa.ForeignKeyConstraint(['author'], ['authors.id'], name='fk_author_annotations_authors_id_author'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('author')
)
op.create_table('book_annotations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('book', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=256), nullable=False),
sa.Column('text', sa.Text(), nullable=False),
sa.Column('file', sa.String(length=256), nullable=True),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_book_annotations_books_id_book'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('book')
)
op.create_table('sequence_infos',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('book', sa.Integer(), nullable=False),
sa.Column('sequence', sa.Integer(), nullable=False),
sa.Column('position', sa.SmallInteger(), nullable=False),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_sequence_infos_books_id_book'),
sa.ForeignKeyConstraint(['sequence'], ['sequences.id'], name='fk_sequence_infos_sequences_id_sequence'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('book', 'sequence', name='uc_sequence_infos_book_sequence')
)
op.create_table('translations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('book', sa.Integer(), nullable=False),
sa.Column('translator', sa.Integer(), nullable=False),
sa.Column('position', sa.SmallInteger(), nullable=False),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_translations_books_id_book'),
sa.ForeignKeyConstraint(['translator'], ['authors.id'], name='fk_translations_authors_id_translator'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('book', 'translator', name='uc_translations_book_translator')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('translations')
op.drop_table('sequence_infos')
op.drop_table('book_annotations')
op.drop_table('author_annotations')
op.drop_table('sequences')
op.drop_table('books')
op.drop_table('authors')
op.drop_table('sources')
# ### end Alembic commands ###