Alter the type for the contents column of stored_file
This was previously set as a Text() which is limited at 65535 [1]. Add a wrapper to use the mysql long text column when applicable (adapted from Heat [3]). [1] https://mariadb.com/kb/en/mariadb/data-types/ [2] http://docs.sqlalchemy.org/en/latest/core/type_basics.html#vendor-specific-types [3] https://github.com/openstack/heat/blob/master/heat/db/sqlalchemy/types.py#L24 Change-Id: I826686e33ba2716108c30ca3dac7ea66f079e1c0 Closes-Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1222718 Co-Authored-By: jason.dobies@redhat.com
This commit is contained in:
parent
413bf52ab4
commit
5216668c80
|
@ -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.')
|
|
@ -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.
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue