forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
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 galaxyproject#18270 from jdavcs/241_merge_24.0
[24.1] Merge 24.0 into 24.1
- Loading branch information
Showing
2 changed files
with
62 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
61 changes: 61 additions & 0 deletions
61
...model/migrations/alembic/versions/1b5bf427db25_add_non_nullable_column_deleted_to_api_.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,61 @@ | ||
"""add non-nullable column deleted to API keys | ||
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, | ||
false, | ||
ForeignKey, | ||
func, | ||
Integer, | ||
select, | ||
) | ||
|
||
from galaxy.model.database_object_names import build_index_name | ||
from galaxy.model.migrations.util import ( | ||
add_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 deleted column | ||
add_column(table_name, Column(column_name, Boolean(), nullable=False, index=True, server_default=false())) | ||
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().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)) | ||
|
||
|
||
def downgrade(): | ||
with transaction(): | ||
drop_index(index_name, table_name) | ||
drop_column(table_name, column_name) |