Add charset and engine settings to every table
Each MySQL table requires setting a default charset and engine, otherwise default values are used. It all worked previously because migration scripts enforce those values to the correct ones. Since we want to be able to generate the schema from models, those MySQL specific parameters must be set. This patch reuses a table_args() function that is already defined. Closes-bug: #1351431 Change-Id: I3dafed9dfe5042fab1cff2ea029ea62c5e5cbea3
This commit is contained in:
parent
0603f74fd9
commit
35d46574ba
@ -21,13 +21,11 @@ import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo.db import exception as db_exc
|
||||
from oslo.db import options as db_options
|
||||
from oslo.db.sqlalchemy import session as db_session
|
||||
from oslo.db.sqlalchemy import utils as db_utils
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from ironic.common import exception
|
||||
from ironic.common import paths
|
||||
from ironic.common import states
|
||||
from ironic.common import utils
|
||||
from ironic.db import api
|
||||
@ -43,9 +41,6 @@ CONF.import_opt('heartbeat_timeout',
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
_DEFAULT_SQL_CONNECTION = 'sqlite:///' + paths.state_path_def('ironic.sqlite')
|
||||
db_options.set_defaults(CONF, _DEFAULT_SQL_CONNECTION, 'ironic.sqlite')
|
||||
|
||||
|
||||
_FACADE = None
|
||||
|
||||
|
@ -21,6 +21,7 @@ SQLAlchemy models for baremetal data.
|
||||
import json
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo.db import options as db_options
|
||||
from oslo.db.sqlalchemy import models
|
||||
import six.moves.urllib.parse as urlparse
|
||||
from sqlalchemy import Boolean, Column, DateTime
|
||||
@ -29,6 +30,8 @@ from sqlalchemy import schema, String, Text
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.types import TypeDecorator, TEXT
|
||||
|
||||
from ironic.common import paths
|
||||
|
||||
|
||||
sql_opts = [
|
||||
cfg.StrOpt('mysql_engine',
|
||||
@ -36,13 +39,17 @@ sql_opts = [
|
||||
help='MySQL engine to use.')
|
||||
]
|
||||
|
||||
_DEFAULT_SQL_CONNECTION = 'sqlite:///' + paths.state_path_def('ironic.sqlite')
|
||||
|
||||
|
||||
cfg.CONF.register_opts(sql_opts, 'database')
|
||||
db_options.set_defaults(cfg.CONF, _DEFAULT_SQL_CONNECTION, 'ironic.sqlite')
|
||||
|
||||
|
||||
def table_args():
|
||||
engine_name = urlparse.urlparse(cfg.CONF.database_connection).scheme
|
||||
engine_name = urlparse.urlparse(cfg.CONF.database.connection).scheme
|
||||
if engine_name == 'mysql':
|
||||
return {'mysql_engine': cfg.CONF.mysql_engine,
|
||||
return {'mysql_engine': cfg.CONF.database.mysql_engine,
|
||||
'mysql_charset': "utf8"}
|
||||
return None
|
||||
|
||||
@ -109,6 +116,7 @@ class Chassis(Base):
|
||||
__tablename__ = 'chassis'
|
||||
__table_args__ = (
|
||||
schema.UniqueConstraint('uuid', name='uniq_chassis0uuid'),
|
||||
table_args()
|
||||
)
|
||||
id = Column(Integer, primary_key=True)
|
||||
uuid = Column(String(36))
|
||||
@ -122,6 +130,7 @@ class Conductor(Base):
|
||||
__tablename__ = 'conductors'
|
||||
__table_args__ = (
|
||||
schema.UniqueConstraint('hostname', name='uniq_conductors0hostname'),
|
||||
table_args()
|
||||
)
|
||||
id = Column(Integer, primary_key=True)
|
||||
hostname = Column(String(255), nullable=False)
|
||||
@ -135,7 +144,8 @@ class Node(Base):
|
||||
__table_args__ = (
|
||||
schema.UniqueConstraint('uuid', name='uniq_nodes0uuid'),
|
||||
schema.UniqueConstraint('instance_uuid',
|
||||
name='uniq_nodes0instance_uuid'))
|
||||
name='uniq_nodes0instance_uuid'),
|
||||
table_args())
|
||||
id = Column(Integer, primary_key=True)
|
||||
uuid = Column(String(36))
|
||||
# NOTE(deva): we store instance_uuid directly on the node so that we can
|
||||
@ -165,7 +175,8 @@ class Port(Base):
|
||||
__tablename__ = 'ports'
|
||||
__table_args__ = (
|
||||
schema.UniqueConstraint('address', name='uniq_ports0address'),
|
||||
schema.UniqueConstraint('uuid', name='uniq_ports0uuid'))
|
||||
schema.UniqueConstraint('uuid', name='uniq_ports0uuid'),
|
||||
table_args())
|
||||
id = Column(Integer, primary_key=True)
|
||||
uuid = Column(String(36))
|
||||
address = Column(String(18))
|
||||
|
Loading…
x
Reference in New Issue
Block a user