-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
5bd2d47
commit c78a8d9
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
invenio_records_lom/alembic/3c1ae3770e92_add_missing_columns.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,54 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 Graz University of Technology. | ||
# | ||
# invenio-records-lom is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Create invenio records lom tables.""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "3c1ae3770e92" | ||
down_revision = "1dc5abf0e34b" | ||
branch_labels = () | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
"""Upgrade database.""" | ||
# step 1: create the columns, but make them nullable for now | ||
op.add_column( | ||
"lom_records_metadata", | ||
sa.Column("deletion_status", sa.String(length=1), nullable=True), | ||
) | ||
op.add_column( | ||
"lom_records_metadata_version", | ||
sa.Column( | ||
"deletion_status", | ||
sa.String(length=1), | ||
nullable=True, | ||
), | ||
) | ||
|
||
# step 2: set default values for existing rows | ||
default_value = "P" | ||
metadata_table = sa.sql.table( | ||
"lom_records_metadata", sa.sql.column("deletion_status") | ||
) | ||
metadata_version_table = sa.sql.table( | ||
"lom_records_metadata_version", sa.sql.column("deletion_status") | ||
) | ||
op.execute(metadata_table.update().values(deletion_status=default_value)) | ||
op.execute(metadata_version_table.update().values(deletion_status=default_value)) | ||
|
||
# step 3: make the original table not nullable | ||
op.alter_column("lom_records_metadata", "deletion_status", nullable=False) | ||
|
||
|
||
def downgrade(): | ||
"""Downgrade database.""" | ||
op.drop_column("lom_records_metadata_version", "deletion_status") | ||
op.drop_column("lom_records_metadata", "deletion_status") |