-
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.
Add deleted column to api_keys table in ToolShed
Since the toolshed uses a duplicated `api_keys` table we sadly need to duplicate the migration too...
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
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
52 changes: 52 additions & 0 deletions
52
lib/tool_shed/webapp/model/migrate/versions/0027_add_api_keys_deleted_column.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,52 @@ | ||
""" | ||
Migration script to add deleted column to API keys | ||
""" | ||
|
||
import datetime | ||
import logging | ||
|
||
from sqlalchemy import ( | ||
Boolean, | ||
Column, | ||
MetaData, | ||
Table, | ||
) | ||
|
||
now = datetime.datetime.utcnow | ||
log = logging.getLogger(__name__) | ||
metadata = MetaData() | ||
|
||
TABLE_NAME = "api_keys" | ||
COLUMN_NAME = "deleted" | ||
|
||
|
||
def upgrade(migrate_engine): | ||
metadata.bind = migrate_engine | ||
print(__doc__) | ||
metadata.reflect() | ||
|
||
deleted_column = Column(COLUMN_NAME, Boolean) | ||
__add_column(deleted_column, TABLE_NAME, metadata) | ||
|
||
|
||
def downgrade(migrate_engine): | ||
metadata.bind = migrate_engine | ||
metadata.reflect() | ||
|
||
__drop_column(COLUMN_NAME, TABLE_NAME, metadata) | ||
|
||
|
||
def __add_column(column, table_name, metadata, **kwds): | ||
try: | ||
table = Table(table_name, metadata, autoload=True) | ||
column.create(table, **kwds) | ||
except Exception: | ||
log.exception("Adding column %s failed.", column) | ||
|
||
|
||
def __drop_column(column_name, table_name, metadata): | ||
try: | ||
table = Table(table_name, metadata, autoload=True) | ||
getattr(table.c, column_name).drop() | ||
except Exception: | ||
log.exception("Dropping column %s failed.", column_name) |