Rename id to alarm_id of Alarm in SqlAlchemy
This change makes the schema more consistent. It also fixes a bug preventig querying alarm_id on /v2/query/alarms API. Closes-Bug: #1282667 Change-Id: Id4d67fa5ee679fe1c8d86b8575a99bfb89e384fa
This commit is contained in:
parent
4d35b21658
commit
5f329a912e
@ -796,7 +796,7 @@ class Connection(base.Connection):
|
||||
|
||||
@staticmethod
|
||||
def _row_to_alarm_model(row):
|
||||
return api_models.Alarm(alarm_id=row.id,
|
||||
return api_models.Alarm(alarm_id=row.alarm_id,
|
||||
enabled=row.enabled,
|
||||
type=row.type,
|
||||
name=row.name,
|
||||
@ -841,7 +841,7 @@ class Connection(base.Connection):
|
||||
if project is not None:
|
||||
query = query.filter(models.Alarm.project_id == project)
|
||||
if alarm_id is not None:
|
||||
query = query.filter(models.Alarm.id == alarm_id)
|
||||
query = query.filter(models.Alarm.alarm_id == alarm_id)
|
||||
|
||||
return self._retrieve_alarms(query)
|
||||
|
||||
@ -852,7 +852,7 @@ class Connection(base.Connection):
|
||||
"""
|
||||
session = self._get_db_session()
|
||||
with session.begin():
|
||||
alarm_row = models.Alarm(id=alarm.alarm_id)
|
||||
alarm_row = models.Alarm(alarm_id=alarm.alarm_id)
|
||||
alarm_row.update(alarm.as_dict())
|
||||
session.add(alarm_row)
|
||||
|
||||
@ -869,7 +869,7 @@ class Connection(base.Connection):
|
||||
alarm.user_id)
|
||||
Connection._create_or_update(session, models.Project,
|
||||
alarm.project_id)
|
||||
alarm_row = session.merge(models.Alarm(id=alarm.alarm_id))
|
||||
alarm_row = session.merge(models.Alarm(alarm_id=alarm.alarm_id))
|
||||
alarm_row.update(alarm.as_dict())
|
||||
|
||||
return self._row_to_alarm_model(alarm_row)
|
||||
@ -882,7 +882,7 @@ class Connection(base.Connection):
|
||||
session = self._get_db_session()
|
||||
with session.begin():
|
||||
session.query(models.Alarm).filter(
|
||||
models.Alarm.id == alarm_id).delete()
|
||||
models.Alarm.alarm_id == alarm_id).delete()
|
||||
|
||||
@staticmethod
|
||||
def _row_to_alarm_change_model(row):
|
||||
|
@ -0,0 +1,28 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# 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 import MetaData
|
||||
from sqlalchemy import Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
users = Table('alarm', meta, autoload=True)
|
||||
users.c.id.alter(name='alarm_id')
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta = MetaData(bind=migrate_engine)
|
||||
users = Table('alarm', meta, autoload=True)
|
||||
users.c.alarm_id.alter(name='id')
|
@ -290,7 +290,7 @@ class Alarm(Base):
|
||||
Index('ix_alarm_user_id', 'user_id'),
|
||||
Index('ix_alarm_project_id', 'project_id'),
|
||||
)
|
||||
id = Column(String(255), primary_key=True)
|
||||
alarm_id = Column(String(255), primary_key=True)
|
||||
enabled = Column(Boolean)
|
||||
name = Column(Text)
|
||||
type = Column(String(50))
|
||||
|
@ -2550,6 +2550,16 @@ class ComplexAlarmQueryTest(AlarmTestBase,
|
||||
self.assertIn(a.name, set(["yellow-alert", "red-alert"]))
|
||||
self.assertTrue(a.enabled)
|
||||
|
||||
def test_filter_for_alarm_id(self):
|
||||
self.add_some_alarms()
|
||||
filter_expr = {"=": {"alarm_id": "0r4ng3"}}
|
||||
|
||||
result = list(self.conn.query_alarms(filter_expr=filter_expr))
|
||||
|
||||
self.assertEqual(1, len(result))
|
||||
for a in result:
|
||||
self.assertEqual(a.alarm_id, "0r4ng3")
|
||||
|
||||
def test_filter_and_orderby(self):
|
||||
self.add_some_alarms()
|
||||
result = list(self.conn.query_alarms(filter_expr={"=":
|
||||
|
Loading…
x
Reference in New Issue
Block a user