Merge "Metadef schema column name is a reserved word in MySQL"
This commit is contained in:
commit
20cdac95d2
@ -507,7 +507,7 @@ class MetadefObjectRepo(object):
|
|||||||
|
|
||||||
# Convert the persisted json schema to a dict of PropertyTypes
|
# Convert the persisted json schema to a dict of PropertyTypes
|
||||||
property_types = {}
|
property_types = {}
|
||||||
json_props = metadata_object['schema']
|
json_props = metadata_object['json_schema']
|
||||||
for id in json_props:
|
for id in json_props:
|
||||||
property_types[id] = fromjson(PropertyType, json_props[id])
|
property_types[id] = fromjson(PropertyType, json_props[id])
|
||||||
|
|
||||||
@ -539,7 +539,7 @@ class MetadefObjectRepo(object):
|
|||||||
'name': metadata_object.name,
|
'name': metadata_object.name,
|
||||||
'required': required_str,
|
'required': required_str,
|
||||||
'description': metadata_object.description,
|
'description': metadata_object.description,
|
||||||
'schema': db_schema
|
'json_schema': db_schema
|
||||||
}
|
}
|
||||||
return db_metadata_object
|
return db_metadata_object
|
||||||
|
|
||||||
@ -694,14 +694,14 @@ class MetadefPropertyRepo(object):
|
|||||||
namespace=namespace_entity,
|
namespace=namespace_entity,
|
||||||
property_id=property['id'],
|
property_id=property['id'],
|
||||||
name=property['name'],
|
name=property['name'],
|
||||||
schema=property['schema']
|
schema=property['json_schema']
|
||||||
)
|
)
|
||||||
|
|
||||||
def _format_metadef_property_to_db(self, property):
|
def _format_metadef_property_to_db(self, property):
|
||||||
|
|
||||||
db_metadata_object = {
|
db_metadata_object = {
|
||||||
'name': property.name,
|
'name': property.name,
|
||||||
'schema': property.schema
|
'json_schema': property.schema
|
||||||
}
|
}
|
||||||
return db_metadata_object
|
return db_metadata_object
|
||||||
|
|
||||||
|
@ -1265,7 +1265,7 @@ def metadef_object_create(context, namespace_name, values):
|
|||||||
object_values = copy.deepcopy(values)
|
object_values = copy.deepcopy(values)
|
||||||
object_name = object_values['name']
|
object_name = object_values['name']
|
||||||
required_attributes = ['name']
|
required_attributes = ['name']
|
||||||
allowed_attributes = ['name', 'description', 'schema', 'required']
|
allowed_attributes = ['name', 'description', 'json_schema', 'required']
|
||||||
|
|
||||||
namespace = metadef_namespace_get(context, namespace_name)
|
namespace = metadef_namespace_get(context, namespace_name)
|
||||||
|
|
||||||
@ -1383,7 +1383,7 @@ def metadef_property_create(context, namespace_name, values):
|
|||||||
property_values = copy.deepcopy(values)
|
property_values = copy.deepcopy(values)
|
||||||
property_name = property_values['name']
|
property_name = property_values['name']
|
||||||
required_attributes = ['name']
|
required_attributes = ['name']
|
||||||
allowed_attributes = ['name', 'description', 'schema', 'required']
|
allowed_attributes = ['name', 'description', 'json_schema', 'required']
|
||||||
|
|
||||||
namespace = metadef_namespace_get(context, namespace_name)
|
namespace = metadef_namespace_get(context, namespace_name)
|
||||||
|
|
||||||
@ -1690,7 +1690,7 @@ def _format_property(values):
|
|||||||
'id': _get_metadef_id(),
|
'id': _get_metadef_id(),
|
||||||
'namespace_id': None,
|
'namespace_id': None,
|
||||||
'name': None,
|
'name': None,
|
||||||
'schema': None
|
'json_schema': None
|
||||||
}
|
}
|
||||||
property.update(values)
|
property.update(values)
|
||||||
return property
|
return property
|
||||||
@ -1720,7 +1720,7 @@ def _format_object(values):
|
|||||||
'namespace_id': None,
|
'namespace_id': None,
|
||||||
'name': None,
|
'name': None,
|
||||||
'description': None,
|
'description': None,
|
||||||
'schema': None,
|
'json_schema': None,
|
||||||
'required': None,
|
'required': None,
|
||||||
'created_at': dt,
|
'created_at': dt,
|
||||||
'updated_at': dt
|
'updated_at': dt
|
||||||
|
@ -200,7 +200,7 @@ def _populate_metadata(meta, metadata_path=None):
|
|||||||
values = {
|
values = {
|
||||||
'name': property,
|
'name': property,
|
||||||
'namespace_id': namespace_id,
|
'namespace_id': namespace_id,
|
||||||
'schema': json.dumps(schema),
|
'json_schema': json.dumps(schema),
|
||||||
'created_at': timeutils.utcnow()
|
'created_at': timeutils.utcnow()
|
||||||
}
|
}
|
||||||
_insert_data_to_db(metadef_properties_table, values)
|
_insert_data_to_db(metadef_properties_table, values)
|
||||||
@ -210,7 +210,7 @@ def _populate_metadata(meta, metadata_path=None):
|
|||||||
'name': object.get('name', None),
|
'name': object.get('name', None),
|
||||||
'description': object.get('description', None),
|
'description': object.get('description', None),
|
||||||
'namespace_id': namespace_id,
|
'namespace_id': namespace_id,
|
||||||
'schema': json.dumps(object.get('properties', None)),
|
'json_schema': json.dumps(object.get('properties', None)),
|
||||||
'created_at': timeutils.utcnow()
|
'created_at': timeutils.utcnow()
|
||||||
}
|
}
|
||||||
_insert_data_to_db(metadef_objects_table, values)
|
_insert_data_to_db(metadef_objects_table, values)
|
||||||
@ -287,7 +287,7 @@ def _export_data_to_file(meta, path):
|
|||||||
objects.append({
|
objects.append({
|
||||||
"name": object['name'],
|
"name": object['name'],
|
||||||
"description": object['description'],
|
"description": object['description'],
|
||||||
"properties": json.loads(object['schema'])
|
"properties": json.loads(object['json_schema'])
|
||||||
})
|
})
|
||||||
values.update({
|
values.update({
|
||||||
'objects': objects
|
'objects': objects
|
||||||
@ -296,7 +296,7 @@ def _export_data_to_file(meta, path):
|
|||||||
properties = {}
|
properties = {}
|
||||||
for property in db_properties:
|
for property in db_properties:
|
||||||
properties.update({
|
properties.update({
|
||||||
property['name']: json.loads(property['schema'])
|
property['name']: json.loads(property['json_schema'])
|
||||||
})
|
})
|
||||||
values.update({
|
values.update({
|
||||||
'properties': properties
|
'properties': properties
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from sqlalchemy.schema import MetaData
|
||||||
|
from sqlalchemy.schema import Table
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(migrate_engine):
|
||||||
|
meta = MetaData(bind=migrate_engine)
|
||||||
|
metadef_objects = Table('metadef_objects', meta, autoload=True)
|
||||||
|
metadef_objects.c.schema.alter(name='json_schema')
|
||||||
|
|
||||||
|
metadef_properties = Table('metadef_properties', meta, autoload=True)
|
||||||
|
metadef_properties.c.schema.alter(name='json_schema')
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(migrate_engine):
|
||||||
|
meta = MetaData(bind=migrate_engine)
|
||||||
|
metadef_objects = Table('metadef_objects', meta, autoload=True)
|
||||||
|
metadef_objects.c.json_schema.alter(name='schema')
|
||||||
|
|
||||||
|
metadef_properties = Table('metadef_properties', meta, autoload=True)
|
||||||
|
metadef_properties.c.json_schema.alter(name='schema')
|
@ -89,7 +89,7 @@ class MetadefObject(BASE_DICT, GlanceMetadefBase):
|
|||||||
name = Column(String(80), nullable=False)
|
name = Column(String(80), nullable=False)
|
||||||
description = Column(Text())
|
description = Column(Text())
|
||||||
required = Column(Text())
|
required = Column(Text())
|
||||||
schema = Column(JSONEncodedDict(), default={})
|
json_schema = Column(JSONEncodedDict(), default={})
|
||||||
|
|
||||||
|
|
||||||
class MetadefProperty(BASE_DICT, GlanceMetadefBase):
|
class MetadefProperty(BASE_DICT, GlanceMetadefBase):
|
||||||
@ -103,7 +103,7 @@ class MetadefProperty(BASE_DICT, GlanceMetadefBase):
|
|||||||
namespace_id = Column(Integer(), ForeignKey('metadef_namespaces.id'),
|
namespace_id = Column(Integer(), ForeignKey('metadef_namespaces.id'),
|
||||||
nullable=False)
|
nullable=False)
|
||||||
name = Column(String(80), nullable=False)
|
name = Column(String(80), nullable=False)
|
||||||
schema = Column(JSONEncodedDict(), default={})
|
json_schema = Column(JSONEncodedDict(), default={})
|
||||||
|
|
||||||
|
|
||||||
class MetadefNamespaceResourceType(BASE_DICT, GlanceMetadefBase):
|
class MetadefNamespaceResourceType(BASE_DICT, GlanceMetadefBase):
|
||||||
|
@ -60,7 +60,7 @@ def build_object_fixture(**kwargs):
|
|||||||
'name': u'test-object-name',
|
'name': u'test-object-name',
|
||||||
'description': u'test-object-description',
|
'description': u'test-object-description',
|
||||||
'required': u'fake-required-properties-list',
|
'required': u'fake-required-properties-list',
|
||||||
'schema': u'{fake-schema}'
|
'json_schema': u'{fake-schema}'
|
||||||
}
|
}
|
||||||
object.update(kwargs)
|
object.update(kwargs)
|
||||||
return object
|
return object
|
||||||
@ -71,7 +71,7 @@ def build_property_fixture(**kwargs):
|
|||||||
property = {
|
property = {
|
||||||
'namespace_id': 1,
|
'namespace_id': 1,
|
||||||
'name': u'test-property-name',
|
'name': u'test-property-name',
|
||||||
'schema': u'{fake-schema}'
|
'json_schema': u'{fake-schema}'
|
||||||
}
|
}
|
||||||
property.update(kwargs)
|
property.update(kwargs)
|
||||||
return property
|
return property
|
||||||
@ -244,7 +244,7 @@ class MetadefPropertyTests(object):
|
|||||||
self.assertEqual(len(found), 2)
|
self.assertEqual(len(found), 2)
|
||||||
|
|
||||||
def test_property_update(self):
|
def test_property_update(self):
|
||||||
delta = {'name': u'New-name', 'schema': u'new-schema'}
|
delta = {'name': u'New-name', 'json_schema': u'new-schema'}
|
||||||
|
|
||||||
fixture_ns = build_namespace_fixture()
|
fixture_ns = build_namespace_fixture()
|
||||||
created_ns = self.db_api.metadef_namespace_create(
|
created_ns = self.db_api.metadef_namespace_create(
|
||||||
@ -263,7 +263,7 @@ class MetadefPropertyTests(object):
|
|||||||
self.context, created_ns['namespace'],
|
self.context, created_ns['namespace'],
|
||||||
created_prop['id'], delta_dict)
|
created_prop['id'], delta_dict)
|
||||||
self.assertEqual(delta['name'], updated['name'])
|
self.assertEqual(delta['name'], updated['name'])
|
||||||
self.assertEqual(delta['schema'], updated['schema'])
|
self.assertEqual(delta['json_schema'], updated['json_schema'])
|
||||||
|
|
||||||
def test_property_delete(self):
|
def test_property_delete(self):
|
||||||
fixture_ns = build_namespace_fixture()
|
fixture_ns = build_namespace_fixture()
|
||||||
@ -354,7 +354,7 @@ class MetadefObjectTests(object):
|
|||||||
self.assertEqual(len(found), 2)
|
self.assertEqual(len(found), 2)
|
||||||
|
|
||||||
def test_object_update(self):
|
def test_object_update(self):
|
||||||
delta = {'name': u'New-name', 'schema': u'new-schema',
|
delta = {'name': u'New-name', 'json_schema': u'new-schema',
|
||||||
'required': u'new-required'}
|
'required': u'new-required'}
|
||||||
|
|
||||||
fixture_ns = build_namespace_fixture()
|
fixture_ns = build_namespace_fixture()
|
||||||
@ -374,7 +374,7 @@ class MetadefObjectTests(object):
|
|||||||
self.context, created_ns['namespace'],
|
self.context, created_ns['namespace'],
|
||||||
created_object['id'], delta_dict)
|
created_object['id'], delta_dict)
|
||||||
self.assertEqual(delta['name'], updated['name'])
|
self.assertEqual(delta['name'], updated['name'])
|
||||||
self.assertEqual(delta['schema'], updated['schema'])
|
self.assertEqual(delta['json_schema'], updated['json_schema'])
|
||||||
|
|
||||||
def test_object_delete(self):
|
def test_object_delete(self):
|
||||||
fixture_ns = build_namespace_fixture()
|
fixture_ns = build_namespace_fixture()
|
||||||
|
@ -62,7 +62,7 @@ def _db_namespace_fixture(**kwargs):
|
|||||||
def _db_property_fixture(name, **kwargs):
|
def _db_property_fixture(name, **kwargs):
|
||||||
property = {
|
property = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'schema': {"type": "string", "title": "title"},
|
'json_schema': {"type": "string", "title": "title"},
|
||||||
}
|
}
|
||||||
property.update(kwargs)
|
property.update(kwargs)
|
||||||
return property
|
return property
|
||||||
@ -72,7 +72,7 @@ def _db_object_fixture(name, **kwargs):
|
|||||||
obj = {
|
obj = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'description': None,
|
'description': None,
|
||||||
'schema': {},
|
'json_schema': {},
|
||||||
'required': '[]',
|
'required': '[]',
|
||||||
}
|
}
|
||||||
obj.update(kwargs)
|
obj.update(kwargs)
|
||||||
|
@ -1132,6 +1132,90 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
|||||||
db_utils.get_table, engine,
|
db_utils.get_table, engine,
|
||||||
'metadef_namespace_resource_types')
|
'metadef_namespace_resource_types')
|
||||||
|
|
||||||
|
def _pre_upgrade_036(self, engine):
|
||||||
|
meta = sqlalchemy.MetaData()
|
||||||
|
meta.bind = engine
|
||||||
|
|
||||||
|
# metadef_objects
|
||||||
|
table = sqlalchemy.Table("metadef_objects", meta, autoload=True)
|
||||||
|
expected_cols = [u'id',
|
||||||
|
u'namespace_id',
|
||||||
|
u'name',
|
||||||
|
u'description',
|
||||||
|
u'required',
|
||||||
|
u'schema',
|
||||||
|
u'created_at',
|
||||||
|
u'updated_at']
|
||||||
|
col_data = [col.name for col in table.columns]
|
||||||
|
self.assertEqual(expected_cols, col_data)
|
||||||
|
|
||||||
|
# metadef_properties
|
||||||
|
table = sqlalchemy.Table("metadef_properties", meta, autoload=True)
|
||||||
|
expected_cols = [u'id',
|
||||||
|
u'namespace_id',
|
||||||
|
u'name',
|
||||||
|
u'schema',
|
||||||
|
u'created_at',
|
||||||
|
u'updated_at']
|
||||||
|
col_data = [col.name for col in table.columns]
|
||||||
|
self.assertEqual(expected_cols, col_data)
|
||||||
|
|
||||||
|
def _check_036(self, engine, data):
|
||||||
|
meta = sqlalchemy.MetaData()
|
||||||
|
meta.bind = engine
|
||||||
|
|
||||||
|
# metadef_objects
|
||||||
|
table = sqlalchemy.Table("metadef_objects", meta, autoload=True)
|
||||||
|
expected_cols = [u'id',
|
||||||
|
u'namespace_id',
|
||||||
|
u'name',
|
||||||
|
u'description',
|
||||||
|
u'required',
|
||||||
|
u'json_schema',
|
||||||
|
u'created_at',
|
||||||
|
u'updated_at']
|
||||||
|
col_data = [col.name for col in table.columns]
|
||||||
|
self.assertEqual(expected_cols, col_data)
|
||||||
|
|
||||||
|
# metadef_properties
|
||||||
|
table = sqlalchemy.Table("metadef_properties", meta, autoload=True)
|
||||||
|
expected_cols = [u'id',
|
||||||
|
u'namespace_id',
|
||||||
|
u'name',
|
||||||
|
u'json_schema',
|
||||||
|
u'created_at',
|
||||||
|
u'updated_at']
|
||||||
|
col_data = [col.name for col in table.columns]
|
||||||
|
self.assertEqual(expected_cols, col_data)
|
||||||
|
|
||||||
|
def _post_downgrade_036(self, engine):
|
||||||
|
meta = sqlalchemy.MetaData()
|
||||||
|
meta.bind = engine
|
||||||
|
|
||||||
|
# metadef_objects
|
||||||
|
table = sqlalchemy.Table("metadef_objects", meta, autoload=True)
|
||||||
|
expected_cols = [u'id',
|
||||||
|
u'namespace_id',
|
||||||
|
u'name',
|
||||||
|
u'description',
|
||||||
|
u'required',
|
||||||
|
u'schema',
|
||||||
|
u'created_at',
|
||||||
|
u'updated_at']
|
||||||
|
col_data = [col.name for col in table.columns]
|
||||||
|
self.assertEqual(expected_cols, col_data)
|
||||||
|
|
||||||
|
# metadef_properties
|
||||||
|
table = sqlalchemy.Table("metadef_properties", meta, autoload=True)
|
||||||
|
expected_cols = [u'id',
|
||||||
|
u'namespace_id',
|
||||||
|
u'name',
|
||||||
|
u'schema',
|
||||||
|
u'created_at',
|
||||||
|
u'updated_at']
|
||||||
|
col_data = [col.name for col in table.columns]
|
||||||
|
self.assertEqual(expected_cols, col_data)
|
||||||
|
|
||||||
|
|
||||||
class TestMysqlMigrations(test_base.MySQLOpportunisticTestCase,
|
class TestMysqlMigrations(test_base.MySQLOpportunisticTestCase,
|
||||||
MigrationsMixin):
|
MigrationsMixin):
|
||||||
|
@ -73,7 +73,7 @@ def _db_namespace_fixture(namespace, **kwargs):
|
|||||||
def _db_property_fixture(name, **kwargs):
|
def _db_property_fixture(name, **kwargs):
|
||||||
obj = {
|
obj = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'schema': {"type": "string", "title": "title"},
|
'json_schema': {"type": "string", "title": "title"},
|
||||||
}
|
}
|
||||||
obj.update(kwargs)
|
obj.update(kwargs)
|
||||||
return obj
|
return obj
|
||||||
@ -83,7 +83,7 @@ def _db_object_fixture(name, **kwargs):
|
|||||||
obj = {
|
obj = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'description': None,
|
'description': None,
|
||||||
'schema': {},
|
'json_schema': {},
|
||||||
'required': '[]',
|
'required': '[]',
|
||||||
}
|
}
|
||||||
obj.update(kwargs)
|
obj.update(kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user