-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15956 from davelopez/23.0_fix_api_keys_deleted_co…
…lumn_nullable Fix nullable deleted column in API Keys table
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
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
39 changes: 39 additions & 0 deletions
39
.../model/migrations/alembic/versions_gxy/b855b714e8b8_make_api_keys_deleted_non_nullable.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,39 @@ | ||
"""make api_keys deleted non nullable | ||
Revision ID: b855b714e8b8 | ||
Revises: 3356bc2ecfc4 | ||
Create Date: 2023-04-19 18:41:13.500332 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
from galaxy.model.migrations.util import ( | ||
alter_column, | ||
transaction, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b855b714e8b8" | ||
down_revision = "3356bc2ecfc4" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
table_name = "api_keys" | ||
column_name = "deleted" | ||
|
||
|
||
def upgrade(): | ||
with transaction(): | ||
# Update any existing rows with a deleted=NULL value to be deleted=True. | ||
# This will expire any existing API keys that didn't have a deleted value set. | ||
table = sa.sql.table(table_name, sa.Column(column_name, sa.Boolean(), nullable=True)) | ||
op.execute(table.update().where(table.c.deleted.is_(None)).values(deleted=True)) | ||
|
||
# Make the column non-nullable. | ||
alter_column(table_name, column_name, existing_type=sa.Boolean(), nullable=False, server_default=sa.false()) | ||
|
||
|
||
def downgrade(): | ||
alter_column(table_name, column_name, existing_type=sa.Boolean(), nullable=True, server_default=None) |