Updated constraints on storage state

Given that the storage state is not based only on the storage state
anymore, the unique constraint on the "identifier" column of the
"cloudkitty_storage_states" table has been dropped. A unique constraint
on the "identifier", "scope_key", "collector" and "fetcher" columns
has been added.

Change-Id: Ifbcc47156541cea6f9e1e5cf75923895d3219f6f
Story: 2005699
Task: 31020
This commit is contained in:
Luka Peschke 2019-05-16 14:31:06 +02:00
parent b42c3a1798
commit 3c585ece1a
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)