mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
add postage constraint to notification history
A not valid constraint only checks against new rows, not existing rows. We can call VALIDATE CONSTRAINT against this new constraint to check the old rows (which we know are good, having run the command from74961781). Adding a normal constraint acquires an ACCESS EXCLUSIVE lock, but validate constraint only needs a SHARE UPDATE EXCLUSIVE lock. see9d4b8961and0a50993ffor more information on marking constraints as not valid.
This commit is contained in:
@@ -1191,7 +1191,13 @@ class Notification(db.Model):
|
||||
reply_to_text = db.Column(db.String, nullable=True)
|
||||
|
||||
postage = db.Column(db.String, nullable=True)
|
||||
CheckConstraint("notification_type != 'letter' or postage in ('first', 'second')")
|
||||
CheckConstraint("""
|
||||
CASE WHEN notification_type = 'letter' THEN
|
||||
postage in ('first', 'second')
|
||||
ELSE
|
||||
postage is null
|
||||
END
|
||||
""")
|
||||
|
||||
__table_args__ = (
|
||||
db.ForeignKeyConstraint(
|
||||
@@ -1445,7 +1451,13 @@ class NotificationHistory(db.Model, HistoryModel):
|
||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), nullable=True)
|
||||
|
||||
postage = db.Column(db.String, nullable=True)
|
||||
CheckConstraint("notification_type != 'letter' or postage in ('first', 'second')")
|
||||
CheckConstraint("""
|
||||
CASE WHEN notification_type = 'letter' THEN
|
||||
postage in ('first', 'second')
|
||||
ELSE
|
||||
postage is null
|
||||
END
|
||||
""")
|
||||
|
||||
__table_args__ = (
|
||||
db.ForeignKeyConstraint(
|
||||
|
||||
Reference in New Issue
Block a user