rename tenant to project in sql
Change is motivated by the need to do an incremental conversion from using tenant to using project as the name. The database is isolated from the API and can be modified without breaking integrations. ADditional work wil be required to get the API to meet the V3 spec without breaking the V2 spec Change-Id: I7cf7695354071f0ea6252be4730ceec3af0a2f35
This commit is contained in:
parent
dd357475fb
commit
56f194aea1
@ -0,0 +1,20 @@
|
||||
import sqlalchemy as sql
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
legacy_table = sql.Table('tenant', meta, autoload=True)
|
||||
legacy_table.rename('project')
|
||||
legacy_table = sql.Table('user_tenant_membership', meta, autoload=True)
|
||||
legacy_table.rename('user_project_membership')
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
"""Replace API-version specific endpoint tables with one based on v2."""
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
upgrade_table = sql.Table('project', meta, autoload=True)
|
||||
upgrade_table.rename('tenant')
|
||||
upgrade_table = sql.Table('user_project_membership', meta, autoload=True)
|
||||
upgrade_table.rename('user_tenant_membership')
|
@ -64,7 +64,7 @@ class Credential(sql.ModelBase, sql.DictBase):
|
||||
user_id = sql.Column(sql.String(64),
|
||||
sql.ForeignKey('user.id'),
|
||||
nullable=False)
|
||||
project_id = sql.Column(sql.String(64), sql.ForeignKey('tenant.id'))
|
||||
project_id = sql.Column(sql.String(64), sql.ForeignKey('project.id'))
|
||||
blob = sql.Column(sql.JsonBlob(), nullable=False)
|
||||
type = sql.Column(sql.String(255), nullable=False)
|
||||
extra = sql.Column(sql.JsonBlob())
|
||||
@ -80,8 +80,7 @@ class Domain(sql.ModelBase, sql.DictBase):
|
||||
|
||||
# TODO(dolph): rename to Project
|
||||
class Tenant(sql.ModelBase, sql.DictBase):
|
||||
# TODO(dolph): rename to project
|
||||
__tablename__ = 'tenant'
|
||||
__tablename__ = 'project'
|
||||
attributes = ['id', 'name']
|
||||
id = sql.Column(sql.String(64), primary_key=True)
|
||||
name = sql.Column(sql.String(64), unique=True, nullable=False)
|
||||
@ -141,12 +140,12 @@ class GroupDomainGrant(sql.ModelBase, BaseGrant):
|
||||
# TODO(dolph): ... do we need this table?
|
||||
class UserTenantMembership(sql.ModelBase, sql.DictBase):
|
||||
"""Tenant membership join table."""
|
||||
__tablename__ = 'user_tenant_membership'
|
||||
__tablename__ = 'user_project_membership'
|
||||
user_id = sql.Column(sql.String(64),
|
||||
sql.ForeignKey('user.id'),
|
||||
primary_key=True)
|
||||
tenant_id = sql.Column(sql.String(64),
|
||||
sql.ForeignKey('tenant.id'),
|
||||
sql.ForeignKey('project.id'),
|
||||
primary_key=True)
|
||||
|
||||
|
||||
|
@ -212,6 +212,30 @@ class SqlUpgradeTests(test.TestCase):
|
||||
self.assertEqual(ref.url, endpoint_extra['%surl' % interface])
|
||||
self.assertEqual(ref.extra, '{}')
|
||||
|
||||
def assertTenantTables(self):
|
||||
self.assertTableExists('tenant')
|
||||
self.assertTableExists('user_tenant_membership')
|
||||
self.assertTableDoesNotExist('project')
|
||||
self.assertTableDoesNotExist('user_project_membership')
|
||||
|
||||
def assertProjectTables(self):
|
||||
self.assertTableExists('project')
|
||||
self.assertTableExists('user_project_membership')
|
||||
self.assertTableDoesNotExist('tenant')
|
||||
self.assertTableDoesNotExist('user_tenant_membership')
|
||||
|
||||
def test_upgrade_tenant_to_project(self):
|
||||
self.upgrade(13)
|
||||
self.assertTenantTables()
|
||||
self.upgrade(14)
|
||||
self.assertProjectTables()
|
||||
|
||||
def test_downgrade_project_to_tenant(self):
|
||||
self.upgrade(14)
|
||||
self.assertProjectTables()
|
||||
self.downgrade(13)
|
||||
self.assertTenantTables()
|
||||
|
||||
def test_upgrade_12_to_13(self):
|
||||
self.upgrade(12)
|
||||
self.upgrade(13)
|
||||
@ -355,10 +379,10 @@ class SqlUpgradeTests(test.TestCase):
|
||||
return s
|
||||
|
||||
def assertTableExists(self, table_name):
|
||||
"""Asserts that a given table exists can be selected by name."""
|
||||
try:
|
||||
self.select_table(table_name)
|
||||
except sqlalchemy.exc.NoSuchTableError:
|
||||
#TODO ayoung: make quoting work for postgres
|
||||
self.engine.execute("select count(*) from '%s'" % table_name)
|
||||
except:
|
||||
raise AssertionError('Table "%s" does not exist' % table_name)
|
||||
|
||||
def assertTableDoesNotExist(self, table_name):
|
||||
|
Loading…
Reference in New Issue
Block a user