-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...end/src/karp/main/migrations/versions/44229cf4d74b_add_unique_constraints_for_entries_.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,28 @@ | ||
"""Add unique constraints for entries tables. | ||
Revision ID: 44229cf4d74b | ||
Revises: e09588a7e6ca | ||
Create Date: 2024-02-05 11:29:56.613345 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mysql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '44229cf4d74b' | ||
down_revision = 'e09588a7e6ca' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
conn = op.get_bind() | ||
for resource_id, table_name in conn.execute( | ||
sa.text("select distinct resource_id, table_name from resources") | ||
): | ||
op.execute(f"alter table {table_name} drop constraint if exists id_version_unique_constraint") | ||
op.create_unique_constraint( | ||
"id_version_unique_constraint", | ||
table_name, | ||
["entity_id", "version"]) |