Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23.1] Add missing TS migration #18267

Merged
merged 4 commits into from
May 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""add non-nullable column deleted to API keys

Check failure on line 1 in lib/tool_shed/webapp/model/migrations/alembic/versions/1b5bf427db25_add_non_nullable_column_deleted_to_api_.py

View workflow job for this annotation

GitHub Actions / Test (3.11)

Imports are incorrectly sorted and/or formatted.

Revision ID: 1b5bf427db25
Revises: 969bbf7bcc29
Create Date: 2024-05-29 21:53:53.516506

"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy import (
Boolean,
Column,
ForeignKey,
Integer,
false,
select,
)
from sqlalchemy import func

from galaxy.model.database_object_names import build_index_name
from galaxy.model.migrations.util import (
add_column,
alter_column,
drop_column,
drop_index,
transaction,
)

# revision identifiers, used by Alembic.
revision = "1b5bf427db25"
down_revision = "969bbf7bcc29"
branch_labels = None
depends_on = None

# database object names used in this revision
table_name = "api_keys"
column_name = "deleted"
index_name = build_index_name(table_name, column_name)


def upgrade():
with transaction():
# Add a nullable deleted column
add_column(table_name, Column(column_name, Boolean(), nullable=True, index=True))
table = sa.sql.table(
table_name,
Column("id", Integer, primary_key=True),
Column("user_id", ForeignKey("galaxy_user.id"), index=True),
Column(column_name, Boolean, index=True, default=False),
)
# Set everything to deleted
op.execute(table.update().where(table.c.deleted.is_(None)).values(deleted=True))
# Select the latest api keys
s = select(func.max(table.c.id)).group_by(table.c.user_id)
# Set all of these api keys to not deleted
op.execute(table.update().where(table.c.id.in_(s)).values(deleted=False))
# Make column not nullable and default to false
alter_column(table_name, column_name, existing_type=Boolean(), nullable=False, server_default=false())


def downgrade():
with transaction():
drop_index(index_name, table_name)
drop_column(table_name, column_name)
Loading