1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
13 import sqlalchemy as sql
16 def upgrade(migrate_engine):
18 meta.bind = migrate_engine
20 # You can specify primary keys when creating tables, however adding
21 # auto-increment integer primary keys for existing tables is not
22 # cross-engine compatibility supported. Thus, the approach is to:
23 # (1) create a new revocation_event table with an int pkey,
24 # (2) migrate data from the old table to the new table,
25 # (3) delete the old revocation_event table
26 # (4) rename the new revocation_event table
27 revocation_table = sql.Table('revocation_event', meta, autoload=True)
29 revocation_table_new = sql.Table(
30 'revocation_event_new',
32 sql.Column('id', sql.Integer, primary_key=True),
33 sql.Column('domain_id', sql.String(64)),
34 sql.Column('project_id', sql.String(64)),
35 sql.Column('user_id', sql.String(64)),
36 sql.Column('role_id', sql.String(64)),
37 sql.Column('trust_id', sql.String(64)),
38 sql.Column('consumer_id', sql.String(64)),
39 sql.Column('access_token_id', sql.String(64)),
40 sql.Column('issued_before', sql.DateTime(), nullable=False),
41 sql.Column('expires_at', sql.DateTime()),
42 sql.Column('revoked_at', sql.DateTime(), index=True, nullable=False),
43 sql.Column('audit_id', sql.String(32), nullable=True),
44 sql.Column('audit_chain_id', sql.String(32), nullable=True))
45 revocation_table_new.create(migrate_engine, checkfirst=True)
47 revocation_table_new.insert().from_select(['domain_id',
59 revocation_table.select())
61 revocation_table.drop()
62 revocation_table_new.rename('revocation_event')