Extend status_description column in Clusters tables

Convert column type to
 * Text for psql - unlimited size
 * LongText for mysql - max size 2^32

Also fixed template for autogenerated migrations: added a blank line to
avoid pep8 violation.

Closes-Bug: #1338933
Change-Id: Ie4c4f57aeb7ff03aa7f6077629f6463a136f8f4b
This commit is contained in:
Dmitry Mescheryakov 2014-06-21 02:46:58 +04:00
parent 0a31b16cd5
commit a9d5f92c22
5 changed files with 65 additions and 1 deletions

View File

@ -29,6 +29,7 @@ from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
${imports if imports else ""} ${imports if imports else ""}
def upgrade(): def upgrade():
${upgrades if upgrades else "pass"} ${upgrades if upgrades else "pass"}

View File

@ -0,0 +1,43 @@
# Copyright 2014 OpenStack Foundation.
#
# 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.
"""convert clusters.status_description to LongText
Revision ID: 007
Revises: 006
Create Date: 2014-06-20 22:36:00.783444
"""
# revision identifiers, used by Alembic.
revision = '007'
down_revision = '006'
from alembic import op
import sqlalchemy as sa
from sahara.db.sqlalchemy import types as st
def upgrade():
op.alter_column('clusters', 'status_description',
type_=st.LongText(), existing_nullable=True,
existing_server_default=None)
def downgrade():
op.alter_column('clusters', 'status_description',
type_=sa.String(length=200), existing_nullable=True,
existing_server_default=None)

View File

@ -62,7 +62,7 @@ class Cluster(mb.SaharaBase):
management_public_key = sa.Column(sa.Text, nullable=False) management_public_key = sa.Column(sa.Text, nullable=False)
user_keypair_id = sa.Column(sa.String(80)) user_keypair_id = sa.Column(sa.String(80))
status = sa.Column(sa.String(80)) status = sa.Column(sa.String(80))
status_description = sa.Column(sa.String(200)) status_description = sa.Column(st.LongText())
info = sa.Column(st.JsonDictType()) info = sa.Column(st.JsonDictType())
extra = sa.Column(st.JsonDictType()) extra = sa.Column(st.JsonDictType())
node_groups = relationship('NodeGroup', cascade="all,delete", node_groups = relationship('NodeGroup', cascade="all,delete",

View File

@ -116,3 +116,9 @@ def LargeBinary():
if base.is_mysql_avail(): if base.is_mysql_avail():
return mysql.LONGBLOB return mysql.LONGBLOB
return sa.LargeBinary return sa.LargeBinary
def LongText():
if base.is_mysql_avail():
return mysql.LONGTEXT
return sa.Text

View File

@ -355,3 +355,17 @@ class TestMigrations(base.BaseWalkMigrationTestCase, base.CommonTestsMixIn):
def _check_006(self, engine, data): def _check_006(self, engine, data):
# currently, 006 is just a placeholder # currently, 006 is just a placeholder
self._check_001(engine, data) self._check_001(engine, data)
def _check_007(self, engine, data):
self._check_001(engine, data)
# check that status_description can keep 128kb.
# MySQL varchar can not keep more then 64kb
desc = 'a' * 128 * 1024 # 128kb
t = db_utils.get_table(engine, 'clusters')
engine.execute(t.insert(), id='123', name='name', plugin_name='plname',
hadoop_version='hversion', management_private_key='1',
management_public_key='2', status_description=desc)
new_desc = engine.execute(t.select()).fetchone().status_description
self.assertEqual(desc, new_desc)
engine.execute(t.delete())