Fix notification method type DB schema migration

The Stein release does away with the concept of built in notifications,
in favour of treating all notification types equally.

This patch fixes an issue with the DB schema migration associated
with this change, which will fail if any notifications using
built-in notification types are configured at the time of the upgrade.

Story: 2006984
Task: 37746
Change-Id: I2e3f08edf1ab6aec526ad93d04effb91ddca600a
This commit is contained in:
Doug Szumski 2019-12-20 15:23:03 +00:00
parent b3fb188fa7
commit 712f693a72
2 changed files with 27 additions and 3 deletions

View File

@ -22,6 +22,8 @@ from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import table
_NM_BUILT_IN_TYPES = set(['EMAIL', 'WEBHOOK', 'PAGERDUTY'])
# revision identifiers, used by Alembic.
revision = '26083b298bb7'
down_revision = 'f69cb3152a76'
@ -34,13 +36,29 @@ _nm_types = table(
sa.String(length=20),
nullable=False))
_nm = table(
'notification_method',
sa.Column('type',
sa.String(length=20),
nullable=False))
def upgrade():
# Built-in notification types have been removed. Here, we
# remove them and rely on monasca_notification to re-populate
# the table according to what is set in its config file.
# remove them (where not in use) and rely on Monasca Notification
# to re-populate the table according to what is set in its config file.
# Start by creating a set of all notification method types currently
# configured in the Monasca DB
connection = op.get_bind()
nm_types_configured = connection.execute(_nm.select()).fetchall()
nm_types_configured = set([nm_type[0] for nm_type in nm_types_configured])
# Remove all built in notification types which are currently *not*
# configured.
nm_types_to_remove = _NM_BUILT_IN_TYPES.difference(nm_types_configured)
op.execute(_nm_types.delete().where(
_nm_types.c.name.in_(('EMAIL', 'WEBHOOK', 'PAGERDUTY'))))
_nm_types.c.name.in_(nm_types_to_remove)))
def downgrade():

View File

@ -0,0 +1,6 @@
---
fixes:
- |
An issue with migrating the DB schema in the Stein release
which can cause an upgrade to fail. See `story
2006984 <https://storyboard.openstack.org/#!/story/2006984>`__