Add indexes

This commit is contained in:
2022-01-03 12:40:58 +03:00
parent 017cc05a19
commit 8188d23405
2 changed files with 29 additions and 2 deletions

View File

@@ -19,6 +19,13 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### 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_books_title"), "books", ["title"], unique=False)
op.create_index(
op.f("ix_books_is_deleted"),
"books",
[sa.text("is_deleted = 'f'")],
unique=False,
)
op.create_index(op.f("ix_books_file_type"), "books", ["file_type"], unique=False)
op.create_index(op.f("ix_sequences_name"), "sequences", ["name"], unique=False) op.create_index(op.f("ix_sequences_name"), "sequences", ["name"], unique=False)
op.create_index( op.create_index(
op.f("tgrm_books_title"), op.f("tgrm_books_title"),
@@ -69,6 +76,20 @@ def upgrade():
unique=False, unique=False,
postgresql_using="btree", postgresql_using="btree",
) )
op.create_index(
op.f("book_sequences_book"),
"book_sequences",
["book"],
unique=False,
postgresql_using="btree",
)
op.create_index(
op.f("book_sequences_sequence"),
"book_sequences",
["sequence"],
unique=False,
postgresql_using="btree",
)
# ### end Alembic commands ### # ### end Alembic commands ###
@@ -76,6 +97,8 @@ def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_sequences_name"), table_name="sequences") 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("ix_books_title"), table_name="books")
op.drop_index(op.f("ix_books_is_deleted"), table_name="books")
op.drop_index(op.f("ix_books_file_type"), table_name="books")
op.drop_index(op.f("tgrm_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_sequences_name"), table_name="books")
op.drop_index(op.f("tgrm_authors_lfm"), table_name="books") op.drop_index(op.f("tgrm_authors_lfm"), table_name="books")
@@ -83,4 +106,6 @@ def downgrade():
op.drop_index(op.f("tgrm_authors_l"), 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_book"), table_name="book_authors")
op.drop_index(op.f("book_authors_author"), table_name="book_authors") op.drop_index(op.f("book_authors_author"), table_name="book_authors")
op.drop_index(op.f("book_sequences_book"), table_name="book_sequences")
op.drop_index(op.f("book_sequences_sequence"), table_name="book_sequences")
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -143,8 +143,10 @@ class Book(ormar.Model):
title: str = ormar.String( title: str = ormar.String(
max_length=256, nullable=False, index=True max_length=256, nullable=False, index=True
) # type: ignore ) # type: ignore
lang: str = ormar.String(max_length=3, nullable=False) # type: ignore lang: str = ormar.String(max_length=3, nullable=False, index=True) # type: ignore
file_type: str = ormar.String(max_length=4, nullable=False) # type: ignore file_type: str = ormar.String(
max_length=4, nullable=False, index=True
) # type: ignore
uploaded: date = ormar.Date() # type: ignore uploaded: date = ormar.Date() # type: ignore
is_deleted: bool = ormar.Boolean( is_deleted: bool = ormar.Boolean(
default=False, server_default=text("false"), nullable=False default=False, server_default=text("false"), nullable=False