Merge "Fix pod_id length inconsistency in data model"
This commit is contained in:
commit
9300f0d88a
tricircle/db
@ -0,0 +1,40 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import migrate
|
||||
from sqlalchemy import MetaData, String, Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
resource_routings = Table('resource_routings', meta, autoload=True)
|
||||
pods = Table('pods', meta, autoload=True)
|
||||
|
||||
col_pod_id_fkey = getattr(resource_routings.c, 'pod_id')
|
||||
col_pod_id_pkey = getattr(pods.c, 'pod_id')
|
||||
|
||||
# In the migration script 002_resource.py, the pod_id string length in
|
||||
# resource_routings table is 64, but pod_id string length in pods table
|
||||
# is 36. The string length in foreign key and primary key isn't the same
|
||||
if col_pod_id_fkey.type.length != col_pod_id_pkey.type.length:
|
||||
# Delete the old constraint. If it exists, we can't modify the
|
||||
# pod_id length.
|
||||
migrate.ForeignKeyConstraint(columns=[resource_routings.c.pod_id],
|
||||
refcolumns=[pods.c.pod_id]).drop()
|
||||
|
||||
col_pod_id_fkey.alter(type=String(col_pod_id_pkey.type.length))
|
||||
|
||||
# Create the foreign key constraint
|
||||
migrate.ForeignKeyConstraint(columns=[resource_routings.c.pod_id],
|
||||
refcolumns=[pods.c.pod_id]).create()
|
@ -0,0 +1,40 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import migrate
|
||||
from sqlalchemy import MetaData, String, Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
cached_endpoints = Table('cached_endpoints', meta, autoload=True)
|
||||
pods = Table('pods', meta, autoload=True)
|
||||
|
||||
col_pod_id_fkey = getattr(cached_endpoints.c, 'pod_id')
|
||||
col_pod_id_pkey = getattr(pods.c, 'pod_id')
|
||||
|
||||
# In the migration script 001_init.py, the pod_id string length in
|
||||
# cached_endpoints table is 64, but pod_id string length in pods table
|
||||
# is 36. The string length in foreign key and primary key isn't the same
|
||||
if col_pod_id_fkey.type.length != col_pod_id_pkey.type.length:
|
||||
# Delete the old constraint. If it exists, we can't modify the
|
||||
# pod_id length.
|
||||
migrate.ForeignKeyConstraint(columns=[cached_endpoints.c.pod_id],
|
||||
refcolumns=[pods.c.pod_id]).drop()
|
||||
|
||||
col_pod_id_fkey.alter(type=String(col_pod_id_pkey.type.length))
|
||||
|
||||
# Create the foreign key constraint
|
||||
migrate.ForeignKeyConstraint(columns=[cached_endpoints.c.pod_id],
|
||||
refcolumns=[pods.c.pod_id]).create()
|
@ -46,7 +46,7 @@ class CachedEndpoint(core.ModelBase, core.DictBase):
|
||||
|
||||
service_id = sql.Column('service_id', sql.String(length=64),
|
||||
primary_key=True)
|
||||
pod_id = sql.Column('pod_id', sql.String(length=64),
|
||||
pod_id = sql.Column('pod_id', sql.String(length=36),
|
||||
sql.ForeignKey('pods.pod_id'),
|
||||
nullable=False)
|
||||
service_type = sql.Column('service_type', sql.String(length=64),
|
||||
@ -72,7 +72,7 @@ class ResourceRouting(core.ModelBase, core.DictBase, models.TimestampMixin):
|
||||
primary_key=True, autoincrement=True)
|
||||
top_id = sql.Column('top_id', sql.String(length=127), nullable=False)
|
||||
bottom_id = sql.Column('bottom_id', sql.String(length=36))
|
||||
pod_id = sql.Column('pod_id', sql.String(length=64),
|
||||
pod_id = sql.Column('pod_id', sql.String(length=36),
|
||||
sql.ForeignKey('pods.pod_id'),
|
||||
nullable=False)
|
||||
project_id = sql.Column('project_id', sql.String(length=36))
|
||||
|
Loading…
x
Reference in New Issue
Block a user