Add linters configs

This commit is contained in:
2022-01-01 20:54:59 +03:00
parent 4a78d4f987
commit cbba30f2af
30 changed files with 580 additions and 298 deletions

View File

@@ -1,20 +1,22 @@
from logging.config import fileConfig
import os
import sys
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 + '/../../')
sys.path.insert(0, myPath + "/../../")
config = context.config
from app.models import BaseMeta
target_metadata = BaseMeta.metadata

View File

@@ -10,35 +10,77 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '08193b547a80'
down_revision = 'b44117a41998'
revision = "08193b547a80"
down_revision = "b44117a41998"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f('ix_books_title'), 'books', ['title'], unique=False)
op.create_index(op.f('ix_sequences_name'), 'sequences', ['name'], unique=False)
op.create_index(op.f('tgrm_books_title'), 'books', ['title'], postgresql_using='gin', postgresql_ops={'description': 'gin_trgm_ops'})
op.create_index(op.f('tgrm_sequences_name'), 'sequences', ['name'], postgresql_using='gin', postgresql_ops={'description': 'gin_trgm_ops'})
op.create_index(op.f('tgrm_authors_lfm'), 'authors', [sa.text("(last_name || ' ' || first_name || ' ' || middle_name)")] ,postgresql_using='gin', postgresql_ops={'description': 'gin_trgm_ops'})
op.create_index(op.f('tgrm_authors_lf'), 'authors', [sa.text("(last_name || ' ' || first_name)")] ,postgresql_using='gin', postgresql_ops={'description': 'gin_trgm_ops'})
op.create_index(op.f('tgrm_authors_l'), 'authors', ['last_name'] ,postgresql_using='gin', postgresql_ops={'description': 'gin_trgm_ops'})
op.create_index(op.f('book_authors_book'), 'book_authors', ['book'], unique=False, postgresql_using='btree')
op.create_index(op.f('book_authors_author'), 'book_authors', ['author'], unique=False, postgresql_using='btree')
op.create_index(op.f("ix_books_title"), "books", ["title"], unique=False)
op.create_index(op.f("ix_sequences_name"), "sequences", ["name"], unique=False)
op.create_index(
op.f("tgrm_books_title"),
"books",
["title"],
postgresql_using="gin",
postgresql_ops={"description": "gin_trgm_ops"},
)
op.create_index(
op.f("tgrm_sequences_name"),
"sequences",
["name"],
postgresql_using="gin",
postgresql_ops={"description": "gin_trgm_ops"},
)
op.create_index(
op.f("tgrm_authors_lfm"),
"authors",
[sa.text("(last_name || ' ' || first_name || ' ' || middle_name)")],
postgresql_using="gin",
postgresql_ops={"description": "gin_trgm_ops"},
)
op.create_index(
op.f("tgrm_authors_lf"),
"authors",
[sa.text("(last_name || ' ' || first_name)")],
postgresql_using="gin",
postgresql_ops={"description": "gin_trgm_ops"},
)
op.create_index(
op.f("tgrm_authors_l"),
"authors",
["last_name"],
postgresql_using="gin",
postgresql_ops={"description": "gin_trgm_ops"},
)
op.create_index(
op.f("book_authors_book"),
"book_authors",
["book"],
unique=False,
postgresql_using="btree",
)
op.create_index(
op.f("book_authors_author"),
"book_authors",
["author"],
unique=False,
postgresql_using="btree",
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_sequences_name'), table_name='sequences')
op.drop_index(op.f('ix_books_title'), table_name='books')
op.drop_index(op.f('tgrm_books_title'), table_name='books')
op.drop_index(op.f('tgrm_sequences_name'), table_name='books')
op.drop_index(op.f('tgrm_authors_lfm'), table_name='books')
op.drop_index(op.f('tgrm_authors_lf'), table_name='books')
op.drop_index(op.f('tgrm_authors_l'), table_name='books')
op.drop_index(op.f('book_authors_book'), table_name='book_authors')
op.drop_index(op.f('book_authors_author'), table_name='book_authors')
op.drop_index(op.f("ix_sequences_name"), table_name="sequences")
op.drop_index(op.f("ix_books_title"), table_name="books")
op.drop_index(op.f("tgrm_books_title"), table_name="books")
op.drop_index(op.f("tgrm_sequences_name"), table_name="books")
op.drop_index(op.f("tgrm_authors_lfm"), table_name="books")
op.drop_index(op.f("tgrm_authors_lf"), table_name="books")
op.drop_index(op.f("tgrm_authors_l"), table_name="books")
op.drop_index(op.f("book_authors_book"), table_name="book_authors")
op.drop_index(op.f("book_authors_author"), table_name="book_authors")
# ### end Alembic commands ###

View File

@@ -11,7 +11,7 @@ from sqlalchemy.sql.schema import UniqueConstraint
# revision identifiers, used by Alembic.
revision = 'b44117a41998'
revision = "b44117a41998"
down_revision = None
branch_labels = None
depends_on = None
@@ -19,128 +19,203 @@ 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(
"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(
"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=3), nullable=False),
sa.Column('file_type', sa.String(length=4), nullable=False),
sa.Column('uploaded', sa.Date(), nullable=False),
sa.Column('is_deleted', sa.Boolean(), server_default=sa.text('false'), 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(
"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=3), nullable=False),
sa.Column("file_type", sa.String(length=4), nullable=False),
sa.Column("uploaded", sa.Date(), nullable=False),
sa.Column(
"is_deleted", sa.Boolean(), server_default=sa.text("false"), 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('genres',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('source', sa.SmallInteger(), nullable=False),
sa.Column('remote_id', sa.Integer(), nullable=False),
sa.Column('code', sa.String(length=45), nullable=False),
sa.Column('description', sa.String(length=99), nullable=False),
sa.Column('meta', sa.String(length=45), nullable=False),
sa.ForeignKeyConstraint(['source'], ['sources.id'], name='fk_genres_sources_id_source'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('source', 'remote_id', name='uc_genres_source_remote_id')
op.create_table(
"genres",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("source", sa.SmallInteger(), nullable=False),
sa.Column("remote_id", sa.Integer(), nullable=False),
sa.Column("code", sa.String(length=45), nullable=False),
sa.Column("description", sa.String(length=99), nullable=False),
sa.Column("meta", sa.String(length=45), nullable=False),
sa.ForeignKeyConstraint(
["source"], ["sources.id"], name="fk_genres_sources_id_source"
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("source", "remote_id", name="uc_genres_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(
"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(
"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(
"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('book_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_book_authors_authors_author_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_book_authors_books_book_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('book', 'author', name='uc_book_authors_book_author'),
op.create_table(
"book_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_book_authors_authors_author_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["book"],
["books.id"],
name="fk_book_authors_books_book_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("book", "author", name="uc_book_authors_book_author"),
)
op.create_table('book_genres',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('genre', sa.Integer(), nullable=True),
sa.Column('book', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_book_genres_books_book_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['genre'], ['genres.id'], name='fk_book_genres_genres_genre_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('book', 'genre', name='uc_book_genres_book_genre'),
op.create_table(
"book_genres",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("genre", sa.Integer(), nullable=True),
sa.Column("book", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["book"],
["books.id"],
name="fk_book_genres_books_book_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["genre"],
["genres.id"],
name="fk_book_genres_genres_genre_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("book", "genre", name="uc_book_genres_book_genre"),
)
op.create_table('book_sequences',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('position', sa.SmallInteger(), nullable=False),
sa.Column('sequence', sa.Integer(), nullable=True),
sa.Column('book', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_book_sequences_books_book_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['sequence'], ['sequences.id'], name='fk_book_sequences_sequences_sequence_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('book', 'sequence', name='uc_book_sequences_book_sequence'),
op.create_table(
"book_sequences",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("position", sa.SmallInteger(), nullable=False),
sa.Column("sequence", sa.Integer(), nullable=True),
sa.Column("book", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["book"],
["books.id"],
name="fk_book_sequences_books_book_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["sequence"],
["sequences.id"],
name="fk_book_sequences_sequences_sequence_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("book", "sequence", name="uc_book_sequences_book_sequence"),
)
op.create_table('translations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('position', sa.SmallInteger(), nullable=False),
sa.Column('author', sa.Integer(), nullable=True),
sa.Column('book', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['author'], ['authors.id'], name='fk_translations_authors_author_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['book'], ['books.id'], name='fk_translations_books_book_id', onupdate='CASCADE', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('book', 'author', name='uc_translations_book_author'),
op.create_table(
"translations",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("position", sa.SmallInteger(), nullable=False),
sa.Column("author", sa.Integer(), nullable=True),
sa.Column("book", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["author"],
["authors.id"],
name="fk_translations_authors_author_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["book"],
["books.id"],
name="fk_translations_books_book_id",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("book", "author", name="uc_translations_book_author"),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('translations')
op.drop_table('book_sequences')
op.drop_table('book_genres')
op.drop_table('book_authors')
op.drop_table('book_annotations')
op.drop_table('author_annotations')
op.drop_table('sequences')
op.drop_table('genres')
op.drop_table('books')
op.drop_table('authors')
op.drop_table('sources')
op.drop_table("translations")
op.drop_table("book_sequences")
op.drop_table("book_genres")
op.drop_table("book_authors")
op.drop_table("book_annotations")
op.drop_table("author_annotations")
op.drop_table("sequences")
op.drop_table("genres")
op.drop_table("books")
op.drop_table("authors")
op.drop_table("sources")
# ### end Alembic commands ###