Skip to content

Commit

Permalink
Add unique db migration
Browse files Browse the repository at this point in the history
Change-Id: Ib1336950b4f4000027593a87b9ac71c02967c6ca
  • Loading branch information
AnishReddyRavula committed Mar 25, 2024
1 parent 74642e1 commit 9d391f7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 OpenStack Foundation.
#
# 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.

"""Add is_unique field in extra capabilities
Revision ID: 9eec70cbc562
Revises: d5a379ff6ba3
Create Date: 2024-03-15 17:36:26.552008
"""

# revision identifiers, used by Alembic.
revision = '9eec70cbc562'
down_revision = 'd5a379ff6ba3'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

def upgrade():
op.create_unique_constraint(None, 'devices', ['name'])
op.add_column('extra_capabilities', sa.Column('is_unique', sa.Boolean(), server_default=sa.text('false'), nullable=False))
# ### end Alembic commands ###


def downgrade():
op.drop_column('extra_capabilities', 'is_unique')
op.drop_constraint(None, 'devices', type_='unique')
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion blazar/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def validate_capability_value(self, key, capability_id):
).first()
if existing_capability:
raise ValueError(
f"{extra_capability.capability_name} must be unique. "
f"Values for {extra_capability.capability_name} must be unique. "
f"Please select unique {extra_capability.capability_name} for "
f"{self.computehost_id}"
)
Expand Down

0 comments on commit 9d391f7

Please sign in to comment.