Change resource.resource_metadata to text type

The existing resource.resource_metadata column size is 5k chars,
which is not enough for some large JSON metadata payload,
so change to as Text column to make sure store all JSON string
without truncating.

Fixes bug #1220683

Change-Id: Ide8c6b94f1ae56d76fe3d5b6238d44e498e67c03
This commit is contained in:
Haomeng, Wang 2013-09-17 07:55:40 +08:00
parent 09e0f3fabf
commit 7f3e7cea0e
2 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,38 @@
# -*- encoding: utf-8 -*-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
# Copyright 2013 IBM Corp.
#
# 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 import String
from sqlalchemy import Text
from sqlalchemy import MetaData
from sqlalchemy import Table
meta = MetaData()
def upgrade(migrate_engine):
meta.bind = migrate_engine
resource = Table('resource', meta, autoload=True)
resource.c.resource_metadata.alter(type=Text)
def downgrade(migrate_engine):
meta.bind = migrate_engine
resource = Table('resource', meta, autoload=True)
resource.c.resource_metadata.alter(type=String(5000))

View File

@ -191,7 +191,7 @@ class Resource(Base):
)
id = Column(String(255), primary_key=True)
sources = relationship("Source", secondary=lambda: sourceassoc)
resource_metadata = Column(JSONEncodedDict(5000))
resource_metadata = Column(JSONEncodedDict())
user_id = Column(String(255), ForeignKey('user.id'))
project_id = Column(String(255), ForeignKey('project.id'))
meters = relationship("Meter", backref='resource')