Merge "downgrade user and tenant normalized tables downgraded such that sqlite is supported, too"
This commit is contained in:
commit
66dbbdcb90
@ -16,19 +16,54 @@
|
||||
|
||||
|
||||
from sqlalchemy import Column, MetaData, String, Table, Text, types
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
||||
#this won't work on sqlite. It doesn't support dropping columns
|
||||
#sqlite doesn't support dropping columns. Copy to a new table instead
|
||||
def downgrade_user_table(meta, migrate_engine):
|
||||
user_table = Table('user', meta, autoload=True)
|
||||
user_table.columns["password"].drop()
|
||||
user_table.columns["enabled"].drop()
|
||||
maker = sessionmaker(bind=migrate_engine)
|
||||
session = maker()
|
||||
session.execute("ALTER TABLE user RENAME TO orig_user;")
|
||||
|
||||
user_table = Table(
|
||||
'user',
|
||||
meta,
|
||||
Column('id', String(64), primary_key=True),
|
||||
Column('name', String(64), unique=True, nullable=False),
|
||||
Column('extra', Text()))
|
||||
user_table.create(migrate_engine, checkfirst=True)
|
||||
|
||||
orig_user_table = Table('orig_user', meta, autoload=True)
|
||||
for user in session.query(orig_user_table):
|
||||
session.execute("insert into user (id, name, extra) "
|
||||
"values ( :id, :name, :extra);",
|
||||
{'id': user.id,
|
||||
'name': user.name,
|
||||
'extra': user.extra})
|
||||
session.execute("drop table orig_user;")
|
||||
|
||||
|
||||
def downgrade_tenant_table(meta, migrate_engine):
|
||||
tenant_table = Table('tenant', meta, autoload=True)
|
||||
tenant_table.columns["description"].drop()
|
||||
tenant_table.columns["enabled"].drop()
|
||||
maker = sessionmaker(bind=migrate_engine)
|
||||
session = maker()
|
||||
session.execute("ALTER TABLE tenant RENAME TO orig_tenant;")
|
||||
|
||||
tenant_table = Table(
|
||||
'tenant',
|
||||
meta,
|
||||
Column('id', String(64), primary_key=True),
|
||||
Column('name', String(64), unique=True, nullable=False),
|
||||
Column('extra', Text()))
|
||||
tenant_table.create(migrate_engine, checkfirst=True)
|
||||
|
||||
orig_tenant_table = Table('orig_tenant', meta, autoload=True)
|
||||
for tenant in session.query(orig_tenant_table):
|
||||
session.execute("insert into tenant (id, name, extra) "
|
||||
"values ( :id, :name, :extra);",
|
||||
{'id': tenant.id,
|
||||
'name': tenant.name,
|
||||
'extra': tenant.extra})
|
||||
session.execute("drop table orig_tenant;")
|
||||
|
||||
|
||||
def upgrade_user_table(meta, migrate_engine):
|
||||
|
@ -1,5 +0,0 @@
|
||||
-- not supported by sqlite, but should be:
|
||||
-- alter TABLE tenant drop column description;
|
||||
-- alter TABLE tenant drop column enabled;
|
||||
-- The downgrade process will fail without valid SQL in this file
|
||||
select count(*) from tenant;
|
@ -121,6 +121,9 @@ class SqlUpgradeTests(test.TestCase):
|
||||
session.commit()
|
||||
|
||||
def test_downgrade_9_to_7(self):
|
||||
self.upgrade(7)
|
||||
self.populate_user_table()
|
||||
self.populate_tenant_table()
|
||||
self.upgrade(9)
|
||||
self.downgrade(7)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user