Rename DB columns: tenant -> project
All occurences of ``tenant_id`` across the neutron database are being renamed to ``project_id``. This neutron_taas change accompanies the neutron change: I87a8ef342ccea004731ba0192b23a8e79bc382dc Change-Id: I71087973031ebe479bbd13e3af6cd079174e28cb Related Blueprint: keystone-v3 Closes-Bug: #1522645
This commit is contained in:
parent
57382befb9
commit
7d016185e0
@ -1 +1 @@
|
||||
2ecce0368a62
|
||||
4086b3cffc01
|
||||
|
@ -0,0 +1,120 @@
|
||||
# Copyright 2016 OpenStack Foundation
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
"""rename tenant to project
|
||||
|
||||
Revision ID: 4086b3cffc01
|
||||
Revises: 2ecce0368a62
|
||||
Create Date: 2016-07-30 22:09:16.372917
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4086b3cffc01'
|
||||
down_revision = '2ecce0368a62'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
from sqlalchemy.engine import reflection
|
||||
|
||||
|
||||
_INSPECTOR = None
|
||||
|
||||
|
||||
def get_inspector():
|
||||
"""Reuse inspector."""
|
||||
|
||||
global _INSPECTOR
|
||||
|
||||
if _INSPECTOR:
|
||||
return _INSPECTOR
|
||||
|
||||
else:
|
||||
bind = op.get_bind()
|
||||
_INSPECTOR = reflection.Inspector.from_engine(bind)
|
||||
|
||||
return _INSPECTOR
|
||||
|
||||
|
||||
def get_tables():
|
||||
"""Returns hardcoded list of tables which have ``tenant_id`` column.
|
||||
|
||||
The list is hard-coded to match the state of the schema when this upgrade
|
||||
script is run.
|
||||
"""
|
||||
|
||||
tables = [
|
||||
'tap_services',
|
||||
'tap_flows',
|
||||
]
|
||||
|
||||
return tables
|
||||
|
||||
|
||||
def get_columns(table):
|
||||
"""Returns list of columns for given table."""
|
||||
inspector = get_inspector()
|
||||
return inspector.get_columns(table)
|
||||
|
||||
|
||||
def get_data():
|
||||
"""Returns combined list of tuples: [(table, column)].
|
||||
|
||||
The list is built from tables with a tenant_id column.
|
||||
"""
|
||||
|
||||
output = []
|
||||
tables = get_tables()
|
||||
for table in tables:
|
||||
columns = get_columns(table)
|
||||
|
||||
for column in columns:
|
||||
if column['name'] == 'tenant_id':
|
||||
output.append((table, column))
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def alter_column(table, column):
|
||||
old_name = 'tenant_id'
|
||||
new_name = 'project_id'
|
||||
|
||||
op.alter_column(
|
||||
table_name=table,
|
||||
column_name=old_name,
|
||||
new_column_name=new_name,
|
||||
existing_type=column['type'],
|
||||
existing_nullable=column['nullable']
|
||||
)
|
||||
|
||||
|
||||
def upgrade():
|
||||
data = get_data()
|
||||
for table, column in data:
|
||||
alter_column(table, column)
|
||||
|
||||
|
||||
def contract_creation_exceptions():
|
||||
"""Special migration for the blueprint to support Keystone V3.
|
||||
|
||||
We drop all tenant_id columns and create project_id columns instead.
|
||||
"""
|
||||
|
||||
return {
|
||||
sa.Column: ['.'.join([table, 'project_id']) for table in get_tables()],
|
||||
sa.Index: get_tables()
|
||||
}
|
@ -14,37 +14,36 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from neutron.api.v2 import attributes as attr
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.db import common_db_mixin as base_db
|
||||
from neutron.db import model_base
|
||||
from neutron.db import models_v2
|
||||
from neutron import manager
|
||||
from neutron_taas.extensions import taas
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy.orm import exc
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TapService(model_base.BASEV2, models_v2.HasId):
|
||||
class TapService(model_base.BASEV2, model_base.HasId,
|
||||
model_base.HasProjectNoIndex):
|
||||
|
||||
# Represents a V2 TapService Object
|
||||
__tablename__ = 'tap_services'
|
||||
tenant_id = sa.Column(sa.String(attr.TENANT_ID_MAX_LEN))
|
||||
name = sa.Column(sa.String(255), nullable=True)
|
||||
description = sa.Column(sa.String(1024), nullable=True)
|
||||
port_id = sa.Column(sa.String(36), nullable=False)
|
||||
|
||||
|
||||
class TapFlow(model_base.BASEV2, models_v2.HasId):
|
||||
class TapFlow(model_base.BASEV2, model_base.HasId,
|
||||
model_base.HasProjectNoIndex):
|
||||
|
||||
# Represents a V2 TapFlow Object
|
||||
__tablename__ = 'tap_flows'
|
||||
tenant_id = sa.Column(sa.String(attr.TENANT_ID_MAX_LEN))
|
||||
name = sa.Column(sa.String(255), nullable=True)
|
||||
description = sa.Column(sa.String(1024), nullable=True)
|
||||
tap_service_id = sa.Column(sa.String(36),
|
||||
|
Loading…
x
Reference in New Issue
Block a user