Skip to content

Commit

Permalink
Merge pull request #15956 from davelopez/23.0_fix_api_keys_deleted_co…
Browse files Browse the repository at this point in the history
…lumn_nullable

Fix nullable deleted column in API Keys table
  • Loading branch information
jdavcs authored Apr 27, 2023
2 parents 45c50c2 + 65984d7 commit 1ef0d66
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10140,7 +10140,7 @@ class APIKeys(Base, RepresentById):
user_id = Column(Integer, ForeignKey("galaxy_user.id"), index=True)
key = Column(TrimmedString(32), index=True, unique=True)
user = relationship("User", back_populates="api_keys")
deleted = Column(Boolean, index=True, default=False)
deleted = Column(Boolean, index=True, server_default=false(), nullable=False)


def copy_list(lst, *args, **kwds):
Expand Down
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)

0 comments on commit 1ef0d66

Please sign in to comment.