diff --git a/tuskar/db/sqlalchemy/migrate_repo/versions/005_fix_stored_file_contents.py b/tuskar/db/sqlalchemy/migrate_repo/versions/005_fix_stored_file_contents.py new file mode 100644 index 00000000..5eeb7b9c --- /dev/null +++ b/tuskar/db/sqlalchemy/migrate_repo/versions/005_fix_stored_file_contents.py @@ -0,0 +1,43 @@ +# 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 oslo_db.sqlalchemy import utils +from sqlalchemy import MetaData + +from tuskar.db.sqlalchemy.types import LongText +from tuskar.openstack.common.gettextutils import _ # noqa +from tuskar.openstack.common import log as logging + + +LOG = logging.getLogger(__name__) + +ENGINE = 'InnoDB' +CHARSET = 'utf8' + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + stored_file = utils.get_table(migrate_engine, 'stored_file') + + try: + LOG.info(repr(stored_file)) + col = stored_file._columns.get('contents') + col.alter(type=LongText) + except Exception: + LOG.info(repr(stored_file)) + LOG.exception(_('Exception while creating table.')) + raise + + +def downgrade(migrate_engine): + raise NotImplementedError('Downgrade is unsupported.') diff --git a/tuskar/db/sqlalchemy/models.py b/tuskar/db/sqlalchemy/models.py index 8775a6a3..84f77ffb 100644 --- a/tuskar/db/sqlalchemy/models.py +++ b/tuskar/db/sqlalchemy/models.py @@ -22,6 +22,8 @@ from sqlalchemy import (Column, ForeignKey, Integer, String, Text) from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship +from tuskar.db.sqlalchemy.types import LongText + sql_opts = [ cfg.StrOpt('mysql_engine', @@ -225,7 +227,7 @@ class StoredFile(Base): uuid = Column(String(length=36), primary_key=True) #: contents contains the full file contents as a string. - contents = Column(Text(), nullable=False) + contents = Column(LongText(), nullable=False) #: Object type flags the type of file that this is, i.e. template or #: environment file. diff --git a/tuskar/db/sqlalchemy/types.py b/tuskar/db/sqlalchemy/types.py new file mode 100644 index 00000000..38216c4d --- /dev/null +++ b/tuskar/db/sqlalchemy/types.py @@ -0,0 +1,24 @@ +# 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.dialects import mysql +from sqlalchemy import types + + +class LongText(types.TypeDecorator): + impl = types.Text + + def load_dialect_impl(self, dialect): + if dialect.name == 'mysql': + return dialect.type_descriptor(mysql.LONGTEXT()) + else: + return self.impl