diff options
author | Wenhao Xu <xuwenhao2008@gmail.com> | 2013-01-22 01:34:44 +0800 |
---|---|---|
committer | Wenhao Xu <xuwenhao2008@gmail.com> | 2013-01-22 16:27:31 +0800 |
commit | 84e5e69e5b19272fe32aa587bc5d8552dbc4797e (patch) | |
tree | 026e5a9a31ef5614b94dca9866c8354b5b4469c0 | |
parent | 254333a78d960fc800a35b4c0680b160da9a956e (diff) | |
download | nova-84e5e69e5b19272fe32aa587bc5d8552dbc4797e.tar.gz nova-84e5e69e5b19272fe32aa587bc5d8552dbc4797e.tar.xz nova-84e5e69e5b19272fe32aa587bc5d8552dbc4797e.zip |
Fix the wrong datatype in task_log table.
Change period_begining and period_ending to Datetime type.
Add the migration script.
Change-Id: Ic5d61d6e7e847a1943825a0cb342b0b015bc0b70
Fixes: bug #1102477
-rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/151_change_task_log_column_type.py | 52 | ||||
-rw-r--r-- | nova/db/sqlalchemy/models.py | 4 |
2 files changed, 54 insertions, 2 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/151_change_task_log_column_type.py b/nova/db/sqlalchemy/migrate_repo/versions/151_change_task_log_column_type.py new file mode 100644 index 000000000..44c3aa41f --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/151_change_task_log_column_type.py @@ -0,0 +1,52 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2013 Wenhao Xu <xuwenhao2008@gmail.com>. +# 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. + +from sqlalchemy import MetaData, String, Table, DateTime +from sqlalchemy.dialects import postgresql + + +def upgrade(migrate_engine): + """Convert period_beginning and period_ending to DateTime.""" + meta = MetaData() + meta.bind = migrate_engine + dialect = migrate_engine.url.get_dialect() + + if dialect is postgresql.dialect: + # We need to handle postresql specially. + # Can't use migrate's alter() because it does not support + # explicit casting + for column in ('period_beginning', 'period_ending'): + migrate_engine.execute( + "ALTER TABLE task_log " + "ALTER COLUMN %s TYPE TIMESTAMP WITHOUT TIME ZONE " + "USING %s::TIMESTAMP WITHOUT TIME ZONE" + % (column, column)) + else: + migrations = Table('task_log', meta, autoload=True) + migrations.c.period_beginning.alter(DateTime) + migrations.c.period_ending.alter(DateTime) + + +def downgrade(migrate_engine): + """Convert columns back to String(255).""" + meta = MetaData() + meta.bind = migrate_engine + + # don't need to handle postgresql here. + migrations = Table('task_log', meta, autoload=True) + migrations.c.period_beginning.alter(String(255)) + migrations.c.period_ending.alter(String(255)) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 5050cb77e..baa966dbc 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -1038,8 +1038,8 @@ class TaskLog(BASE, NovaBase): task_name = Column(String(255), nullable=False) state = Column(String(255), nullable=False) host = Column(String(255)) - period_beginning = Column(String(255), default=timeutils.utcnow) - period_ending = Column(String(255), default=timeutils.utcnow) + period_beginning = Column(DateTime, default=timeutils.utcnow) + period_ending = Column(DateTime, default=timeutils.utcnow) message = Column(String(255), nullable=False) task_items = Column(Integer(), default=0) errors = Column(Integer(), default=0) |