Enforce NOT NULL constraint on notification_status#4908
Conversation
8fce946 to
e9e818f
Compare
81f9491 to
661c1ca
Compare
| ) | ||
| op.execute("ALTER TABLE notifications ALTER COLUMN notification_status SET NOT NULL;") | ||
|
|
||
| with op.get_context().autocommit_block(): |
There was a problem hiding this comment.
Notifications table only handles INSERT and UPDATE operations, PostgreSQL’s default replica identity already includes all required columns (template_id, notification_status, created_at) in the wal2json stream using our existing id primary key.
The DELETE operations are for archiving notifications to notification_history where notification_status counts must remain unchanged, so our aggregator can simply ignore all delete logs.
I think in this case we can skip this migration and it also saves write overhead on notifications table.
There was a problem hiding this comment.
😕 the default replica identity is simply id, is it not? And as such we don't get the old values for the status field in the wal2json stream, which we need for bookkeeping so we know which field in the status table to decrement as a notification moves to another status.
I agree it's a shame this increases our write load slightly, but I don't think there's another way.
There was a problem hiding this comment.
Yeah unfortunately, only returns ID so without this index there is no other way to get the old values.
278215e to
fb582fd
Compare
e9e818f to
e3ccbdf
Compare
|
The base branch for this has now been changed to |
e3ccbdf to
0aab4a5
Compare
whpearson
left a comment
There was a problem hiding this comment.
Change makes sense. Shouldn't lock the notifications table.Tested locally
|
I don't understand the name of the migration |
0aab4a5 to
53ecfa1
Compare
53ecfa1 to
3bf4a5a
Compare
fc0c862 to
6f49b5a
Compare
|
@risicle - migrations have been split up |
6f49b5a to
215a5af
Compare
…nd create unique index on notifications
215a5af to
772484d
Compare
What
Enforce NOT NULL constraint on notification_status
Why
Without NOT NULL - we cannot create an index for notification_status column
Checked DB:
Context
This is needed as we need to implement the following replica identity:
Without adding this index we would have to put the replica on the whole table which will keep track of old values of every column which is not needed.