-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add index concurrently for n_hist * fix --------- Co-authored-by: William B <[email protected]>
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
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,40 @@ | ||
""" | ||
Revision ID: 0439_add_index_n_history | ||
Revises: 0438_sms_templates_msgs_left | ||
Create Date: 2023-10-05 00:00:00 | ||
""" | ||
from datetime import datetime | ||
|
||
from alembic import op | ||
|
||
revision = "0444_add_index_n_history2" | ||
down_revision = "0443_add_apikey_last_used_column" | ||
|
||
|
||
def index_exists(name): | ||
connection = op.get_bind() | ||
result = connection.execute( | ||
"SELECT exists(SELECT 1 from pg_indexes where indexname = '{}') as ix_exists;".format(name) | ||
).first() | ||
return result.ix_exists | ||
|
||
|
||
# option 1 | ||
def upgrade(): | ||
op.execute("COMMIT") | ||
if not index_exists("ix_notification_history_api_key_id_created"): | ||
op.create_index( | ||
op.f("ix_notification_history_api_key_id_created"), | ||
"notification_history", | ||
["api_key_id", "created_at"], | ||
postgresql_concurrently=True, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.execute("COMMIT") | ||
op.drop_index( | ||
op.f("ix_notification_history_api_key_id_created"), table_name="notification_history", postgresql_concurrently=True | ||
) |