From 898a0a874107cef1904b502abdd1139d378e506c Mon Sep 17 00:00:00 2001 From: gordon chung Date: Fri, 26 Jun 2015 14:59:59 -0400 Subject: [PATCH] restore long uuid data type partial revert of Iffd6001c337fa692cc3925778eeb98dda46b2c78. we are not able to revert the patch to support those chasing trunk. this patch makes original migration a noop for future cases and adds a follow up script to revert migration if already applied. it does not revert ids that are under the domain of ceilometer and are known to be within 128 char length, specifically: - message_id - message_signature - event_id (alarm) - alarm_id Change-Id: I8c191adb897f27a1ce0f199ed35253324a5c3809 Closes-Bug: 1468916 --- .../versions/043_reduce_uuid_data_types.py | 28 +++----------- .../044_restore_long_uuid_data_types.py | 37 +++++++++++++++++++ ceilometer/storage/sqlalchemy/models.py | 18 ++++----- 3 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 ceilometer/storage/sqlalchemy/migrate_repo/versions/044_restore_long_uuid_data_types.py diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/043_reduce_uuid_data_types.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/043_reduce_uuid_data_types.py index 75638418..03a5525b 100644 --- a/ceilometer/storage/sqlalchemy/migrate_repo/versions/043_reduce_uuid_data_types.py +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/043_reduce_uuid_data_types.py @@ -10,28 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -from sqlalchemy import MetaData -from sqlalchemy import String -from sqlalchemy import Table - def upgrade(migrate_engine): - meta = MetaData(bind=migrate_engine) - resource = Table('resource', meta, autoload=True) - resource.c.user_id.alter(type=String(128)) - resource.c.project_id.alter(type=String(128)) - resource.c.resource_id.alter(type=String(128)) - resource.c.source_id.alter(type=String(128)) - sample = Table('sample', meta, autoload=True) - sample.c.message_signature.alter(type=String(64)) - sample.c.message_id.alter(type=String(128)) - alarm = Table('alarm', meta, autoload=True) - alarm.c.alarm_id.alter(type=String(128)) - alarm.c.user_id.alter(type=String(128)) - alarm.c.project_id.alter(type=String(128)) - alarm_history = Table('alarm_history', meta, autoload=True) - alarm_history.c.alarm_id.alter(type=String(128)) - alarm_history.c.user_id.alter(type=String(128)) - alarm_history.c.project_id.alter(type=String(128)) - alarm_history.c.event_id.alter(type=String(128)) - alarm_history.c.on_behalf_of.alter(type=String(128)) + # NOTE(gordc): this is a noop script to handle bug1468916 + # previous lowering of id length will fail if db contains data longer. + # this skips migration for those failing. the next script will resize + # if this original migration passed. + pass diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/044_restore_long_uuid_data_types.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/044_restore_long_uuid_data_types.py new file mode 100644 index 00000000..a7db70cb --- /dev/null +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/044_restore_long_uuid_data_types.py @@ -0,0 +1,37 @@ +# 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 MetaData +from sqlalchemy import String +from sqlalchemy import Table + + +def upgrade(migrate_engine): + meta = MetaData(bind=migrate_engine) + resource = Table('resource', meta, autoload=True) + resource.c.user_id.alter(type=String(255)) + resource.c.project_id.alter(type=String(255)) + resource.c.resource_id.alter(type=String(255)) + resource.c.source_id.alter(type=String(255)) + sample = Table('sample', meta, autoload=True) + sample.c.message_signature.alter(type=String(64)) + sample.c.message_id.alter(type=String(128)) + alarm = Table('alarm', meta, autoload=True) + alarm.c.alarm_id.alter(type=String(128)) + alarm.c.user_id.alter(type=String(255)) + alarm.c.project_id.alter(type=String(255)) + alarm_history = Table('alarm_history', meta, autoload=True) + alarm_history.c.alarm_id.alter(type=String(128)) + alarm_history.c.user_id.alter(type=String(255)) + alarm_history.c.project_id.alter(type=String(255)) + alarm_history.c.event_id.alter(type=String(128)) + alarm_history.c.on_behalf_of.alter(type=String(255)) diff --git a/ceilometer/storage/sqlalchemy/models.py b/ceilometer/storage/sqlalchemy/models.py index a23c2ecf..7dcc8f54 100644 --- a/ceilometer/storage/sqlalchemy/models.py +++ b/ceilometer/storage/sqlalchemy/models.py @@ -177,10 +177,10 @@ class Resource(Base): ) internal_id = Column(Integer, primary_key=True) - user_id = Column(String(128)) - project_id = Column(String(128)) - source_id = Column(String(128)) - resource_id = Column(String(128), nullable=False) + user_id = Column(String(255)) + project_id = Column(String(255)) + source_id = Column(String(255)) + resource_id = Column(String(255), nullable=False) resource_metadata = deferred(Column(JSONEncodedDict())) metadata_hash = deferred(Column(String(32))) samples = relationship("Sample", backref="resource") @@ -261,8 +261,8 @@ class Alarm(Base): description = Column(Text) timestamp = Column(PreciseTimestamp, default=lambda: timeutils.utcnow()) - user_id = Column(String(128)) - project_id = Column(String(128)) + user_id = Column(String(255)) + project_id = Column(String(255)) state = Column(String(255)) state_timestamp = Column(PreciseTimestamp, @@ -285,9 +285,9 @@ class AlarmChange(Base): ) event_id = Column(String(128), primary_key=True) alarm_id = Column(String(128)) - on_behalf_of = Column(String(128)) - project_id = Column(String(128)) - user_id = Column(String(128)) + on_behalf_of = Column(String(255)) + project_id = Column(String(255)) + user_id = Column(String(255)) type = Column(String(20)) detail = Column(Text) timestamp = Column(PreciseTimestamp, default=lambda: timeutils.utcnow())