-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to add loan_identifier columns.
- Loading branch information
1 parent
608cdac
commit 7938839
Showing
2 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
alembic/versions/20240821_7a2fcaac8b63_add_loan_identifier_column_to_playtime_tables.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,102 @@ | ||
"""Add loan_identifier column to playtime tables. | ||
Revision ID: 7a2fcaac8b63 | ||
Revises: 7ba553f3f80d | ||
Create Date: 2024-08-21 23:23:48.085451+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.orm.session import Session | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "7a2fcaac8b63" | ||
down_revision = "7ba553f3f80d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
session = Session(bind=op.get_bind()) | ||
conn = session.connection() | ||
|
||
op.add_column( | ||
"playtime_entries", | ||
sa.Column("loan_identifier", sa.String(length=50), nullable=False, default=""), | ||
) | ||
|
||
op.drop_constraint( | ||
"unique_playtime_entry", | ||
"playtime_entries", | ||
) | ||
|
||
op.create_unique_constraint( | ||
"unique_playtime_entry", | ||
"playtime_entries", | ||
[ | ||
"tracking_id", | ||
"identifier_str", | ||
"collection_name", | ||
"library_name", | ||
"loan_identifier", | ||
], | ||
) | ||
|
||
op.add_column( | ||
"playtime_summaries", | ||
sa.Column("loan_identifier", sa.String(length=50), nullable=False, default=""), | ||
) | ||
|
||
op.drop_constraint( | ||
"unique_playtime_summary", | ||
"playtime_summaries", | ||
) | ||
|
||
op.create_unique_constraint( | ||
"unique_playtime_summary", | ||
"playtime_summaries", | ||
[ | ||
"timestamp", | ||
"identifier_str", | ||
"collection_name", | ||
"library_name", | ||
"loan_identifier", | ||
], | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
session = Session(bind=op.get_bind()) | ||
conn = session.connection() | ||
|
||
op.drop_constraint( | ||
"unique_playtime_entry", | ||
"playtime_entries", | ||
) | ||
|
||
op.drop_column("playtime_entries", "loan_identifier") | ||
|
||
op.create_unique_constraint( | ||
"unique_playtime_entry", | ||
"playtime_entries", | ||
[ | ||
"tracking_id", | ||
"timestamp", | ||
"identifier_str", | ||
"collection_name", | ||
"library_name", | ||
], | ||
) | ||
|
||
op.drop_constraint( | ||
"unique_playtime_summary", | ||
"playtime_summaries", | ||
) | ||
|
||
op.drop_column("playtime_summaries", "loan_identifier") | ||
|
||
op.create_unique_constraint( | ||
"unique_playtime_summary", | ||
"playtime_summaries", | ||
["timestamp", "identifier_str", "collection_name", "library_name"], | ||
) |
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