Merge "Updated constraints on storage state"

This commit is contained in:
Zuul 2019-05-17 14:21:17 +00:00 committed by Gerrit Code Review
commit 8f3d130892
2 changed files with 60 additions and 3 deletions

View File

@ -0,0 +1,46 @@
# Copyright 2019 Objectif Libre
#
# 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.
"""Update storage state constraint
Revision ID: c50ed2c19204
Revises: d9d103dd4dcf
Create Date: 2019-05-15 17:02:56.595274
"""
from alembic import op
import six
from cloudkitty.storage_state import models
# revision identifiers, used by Alembic.
revision = 'c50ed2c19204'
down_revision = 'd9d103dd4dcf'
branch_labels = None
depends_on = None
def upgrade():
for name, table in six.iteritems(models.Base.metadata.tables):
if name == 'cloudkitty_storage_states':
with op.batch_alter_table(name,
copy_from=table,
recreate='always') as batch_op:
batch_op.alter_column('identifier')
batch_op.create_unique_constraint(
'uq_cloudkitty_storage_states_identifier',
['identifier', 'scope_key', 'collector', 'fetcher'])
break

View File

@ -18,6 +18,7 @@
from oslo_db.sqlalchemy import models
import sqlalchemy
from sqlalchemy.ext import declarative
from sqlalchemy import schema
Base = declarative.declarative_base()
@ -25,15 +26,25 @@ Base = declarative.declarative_base()
class IdentifierState(Base, models.ModelBase):
"""Represents the state of a given identifier."""
__table_args__ = {'mysql_charset': "utf8",
'mysql_engine': "InnoDB"}
@declarative.declared_attr
def __table_args__(cls):
return (
schema.UniqueConstraint(
'identifier',
'scope_key',
'collector',
'fetcher',
name='uq_cloudkitty_storage_states_identifier'),
)
__tablename__ = 'cloudkitty_storage_states'
id = sqlalchemy.Column(sqlalchemy.Integer,
primary_key=True)
identifier = sqlalchemy.Column(sqlalchemy.String(256),
nullable=False,
unique=True)
unique=False)
scope_key = sqlalchemy.Column(sqlalchemy.String(40),
nullable=True,
unique=False)