-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:notarious2/fastapi-chat
- Loading branch information
Showing
5 changed files
with
270 additions
and
12 deletions.
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
alembic/versions/0006_create_indexes_increase_user_image_char_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
"""Create indexes, Increase user_image char length | ||
Revision ID: 0006 | ||
Revises: 0005 | ||
Create Date: 2024-02-25 04:37:53.273850 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "0006" | ||
down_revision: Union[str, None] = "0005" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.execute("COMMIT") # to run concurrently | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_index( | ||
"idx_chat_on_guid", | ||
"chat", | ||
["guid"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.create_index( | ||
"idx_chat_on_is_deleted_chat_type", | ||
"chat", | ||
["is_deleted", "chat_type"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.create_index( | ||
"idx_message_on_chat_id", | ||
"message", | ||
["chat_id"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.create_index( | ||
"idx_message_on_user_id", | ||
"message", | ||
["user_id"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.create_index( | ||
"idx_message_on_user_id_chat_id", | ||
"message", | ||
["chat_id", "user_id"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.create_index( | ||
"idx_read_status_on_chat_id", | ||
"read_status", | ||
["chat_id"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.create_index( | ||
"idx_read_status_on_user_id", | ||
"read_status", | ||
["user_id"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.alter_column( | ||
"user", | ||
"user_image", | ||
existing_type=sa.VARCHAR(length=1000), | ||
type_=sa.String(length=1048), | ||
existing_nullable=True, | ||
schema="chat", | ||
) | ||
op.create_index( | ||
"idx_user_on_email_username", | ||
"user", | ||
["email", "username"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_not_exists=True, | ||
) | ||
op.create_index( | ||
"idx_user_partial_on_email_not_deleted", | ||
"user", | ||
["email", "is_deleted"], | ||
unique=False, | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
postgresql_where=sa.text("is_deleted IS false"), | ||
if_not_exists=True, | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
op.execute("COMMIT") # to run concurrently | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index( | ||
"idx_user_partial_on_email_not_deleted", | ||
table_name="user", | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
postgresql_where=sa.text("is_deleted IS false"), | ||
if_exists=True, | ||
) | ||
op.drop_index( | ||
"idx_user_on_email_username", table_name="user", schema="chat", postgresql_concurrently=True, if_exists=True | ||
) | ||
op.alter_column( | ||
"user", | ||
"user_image", | ||
existing_type=sa.String(length=1048), | ||
type_=sa.VARCHAR(length=1000), | ||
existing_nullable=True, | ||
schema="chat", | ||
) | ||
op.drop_index( | ||
"idx_read_status_on_user_id", | ||
table_name="read_status", | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_exists=True, | ||
) | ||
op.drop_index( | ||
"idx_read_status_on_chat_id", | ||
table_name="read_status", | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_exists=True, | ||
) | ||
op.drop_index( | ||
"idx_message_on_user_id_chat_id", | ||
table_name="message", | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_exists=True, | ||
) | ||
op.drop_index( | ||
"idx_message_on_user_id", table_name="message", schema="chat", postgresql_concurrently=True, if_exists=True | ||
) | ||
op.drop_index( | ||
"idx_message_on_chat_id", table_name="message", schema="chat", postgresql_concurrently=True, if_exists=True | ||
) | ||
op.drop_index( | ||
"idx_chat_on_is_deleted_chat_type", | ||
table_name="chat", | ||
schema="chat", | ||
postgresql_concurrently=True, | ||
if_exists=True, | ||
) | ||
op.drop_index("idx_chat_on_guid", table_name="chat", schema="chat", postgresql_concurrently=True, if_exists=True) | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters