Add user delete database migrations
Apart from adding the delete-related columns, this migration replaces the existing unique constraint on the username with a unique index which has a WHERE clause, so that deleted usernames need not be unique. This is to avoid having to implement a special function for generating unique IDs just to keep the deleted username unique and under 30 chars. The deleted username can still use e.g. the initial part of the user_id but the uniqueness is not required.
This commit is contained in:
parent
8b78a74874
commit
5336f65ca4
5
migrations/009.user-deleted.down.sql
Normal file
5
migrations/009.user-deleted.down.sql
Normal file
@ -0,0 +1,5 @@
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS is_deleted;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS deleted_on;
|
||||
|
||||
DROP INDEX IF EXISTS users_username_idx;
|
||||
ALTER TABLE users ADD CONSTRAINT users_username_key UNIQUE (username);
|
5
migrations/009.user-deleted.up.sql
Normal file
5
migrations/009.user-deleted.up.sql
Normal file
@ -0,0 +1,5 @@
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS is_deleted boolean NOT NULL DEFAULT(false);
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS deleted_on timestamp NULL;
|
||||
|
||||
ALTER TABLE users DROP CONSTRAINT IF EXISTS users_username_key;
|
||||
CREATE UNIQUE INDEX users_username_idx ON users (username) WHERE NOT is_deleted;
|
Loading…
Reference in New Issue
Block a user