103 lines
3.8 KiB
Python
103 lines
3.8 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
#
|
|
|
|
"""Split Access and Refresh tokens to separate tables.
|
|
Remove is_active fields as unnecessary.
|
|
Expired access tokens and authorization codes will be hard deleted.
|
|
Refresh tokens should live forever.
|
|
|
|
Revision ID: 013
|
|
Revises: 012
|
|
Create Date: 2014-04-09 13:01:18.536369
|
|
|
|
"""
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '013'
|
|
down_revision = '012'
|
|
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
MYSQL_ENGINE = 'InnoDB'
|
|
MYSQL_CHARSET = 'utf8'
|
|
|
|
|
|
def upgrade(active_plugins=None, options=None):
|
|
|
|
### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table(
|
|
'accesstokens',
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('access_token', sa.Unicode(length=100), nullable=False),
|
|
sa.Column('expires_in', sa.Integer(), nullable=False),
|
|
sa.Column('expires_at', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
mysql_default_charset=MYSQL_CHARSET,
|
|
mysql_engine=MYSQL_ENGINE)
|
|
|
|
op.create_table(
|
|
'refreshtokens',
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('refresh_token', sa.Unicode(length=100), nullable=False),
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
mysql_default_charset=MYSQL_CHARSET,
|
|
mysql_engine=MYSQL_ENGINE)
|
|
|
|
op.drop_table(u'bearertokens')
|
|
op.drop_column(u'authorizationcodes', u'is_active')
|
|
|
|
### end Alembic commands ###
|
|
|
|
|
|
def downgrade(active_plugins=None, options=None):
|
|
|
|
### commands auto generated by Alembic - please adjust! ###
|
|
|
|
op.add_column(u'authorizationcodes',
|
|
sa.Column('is_active', sa.Boolean(), default=True,
|
|
server_default="1",
|
|
nullable=False))
|
|
op.create_table(
|
|
u'bearertokens',
|
|
sa.Column(u'created_at', sa.DateTime(), nullable=True),
|
|
sa.Column(u'updated_at', sa.DateTime(), nullable=True),
|
|
sa.Column(u'id', sa.Integer(), nullable=False),
|
|
sa.Column(u'user_id', sa.Integer(), nullable=False),
|
|
sa.Column(u'access_token', sa.Unicode(length=100), nullable=False),
|
|
sa.Column(u'refresh_token', sa.Unicode(length=100), nullable=False),
|
|
sa.Column(u'expires_in', sa.Integer(), nullable=False),
|
|
sa.Column(u'expires_at', sa.DateTime(), nullable=False),
|
|
sa.Column(u'is_active', sa.Column('is_active', sa.Boolean(),
|
|
default=True,
|
|
server_default="1",
|
|
nullable=False)),
|
|
sa.ForeignKeyConstraint(['user_id'], [u'users.id'],
|
|
name=u'bearertokens_ibfk_1'),
|
|
sa.PrimaryKeyConstraint(u'id'),
|
|
mysql_default_charset=MYSQL_CHARSET,
|
|
mysql_engine=MYSQL_ENGINE)
|
|
|
|
op.drop_table('refreshtokens')
|
|
op.drop_table('accesstokens')
|
|
### end Alembic commands ###
|