Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migrate script for the OAuth2 table.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
lib/galaxy/model/migrate/versions/0135_add_oauth2_table.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,45 @@ | ||
""" | ||
Migration script to add a new table named `galaxy_user_oauth2` for authentication and authorization. | ||
""" | ||
from __future__ import print_function | ||
|
||
import logging | ||
|
||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, MetaData, Table, TEXT | ||
|
||
log = logging.getLogger( __name__ ) | ||
metadata = MetaData() | ||
|
||
UserOAuth2Table = Table( | ||
"galaxy_user_oauth2", metadata, | ||
Column( "id", Integer, primary_key=True ), | ||
Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), nullable=False, index=True ), | ||
Column( "provider", TEXT, nullable=False ), | ||
Column( "state_token", TEXT, nullable=False, index=True ), | ||
Column( "id_token", TEXT, nullable=False ), | ||
Column( "refresh_token", TEXT, nullable=False ), | ||
Column( "expiration_date", DateTime, nullable=False ), | ||
Column( "access_token", TEXT ) ) | ||
|
||
|
||
def upgrade( migrate_engine ): | ||
print( __doc__ ) | ||
metadata.bind = migrate_engine | ||
metadata.reflect() | ||
|
||
# Create UserOAuth2Table | ||
try: | ||
UserOAuth2Table.create() | ||
except Exception as e: | ||
log.exception( "Creating UserOAuth2 table failed: %s" % str( e ) ) | ||
|
||
|
||
def downgrade( migrate_engine ): | ||
metadata.bind = migrate_engine | ||
metadata.reflect() | ||
|
||
# Drop UserOAuth2Table | ||
try: | ||
UserOAuth2Table.drop() | ||
except Exception as e: | ||
log.exception( "Dropping UserOAuth2 table failed: %s" % str( e ) ) |