You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ALTERTABLE IF EXISTS foo ADD COLUMN IF NOT EXISTS bar textCONSTRAINT foo_bar_unique UNIQUE;
also blocks updates while the index is built
❯ cat unique.sql
ALTER TABLE IF EXISTS foo ADD COLUMN IF NOT EXISTS bar text CONSTRAINT foo_bar_unique UNIQUE;
❯ squawk unique.sql
Found 0 issues in 1 file 🎉
❯ squawk --version
squawk 0.26.0
Solution:
split into 3 steps:
step 1 - create column without constraint
ALTERTABLE IF EXISTS foo ADD COLUMN IF NOT EXISTS bar text;
step 2 - add unique index concurrently
-- allows reads and writes while index is builtCREATEUNIQUE INDEXCONCURRENTLY IF NOT EXISTS foo_bar_idx ON foo (bar);
step 3 - create table constraint from unique index
ALTERTABLE foo ADD CONSTRAINT foo_bar_unique UNIQUE USING INDEX foo_bar_idx;
-- NOTICE: ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index "foo_bar_idx" to "foo_bar_unique"
also blocks updates while the index is built
Solution:
split into 3 steps:
step 1 - create column without constraint
step 2 - add unique index concurrently
step 3 - create table constraint from unique index
The text was updated successfully, but these errors were encountered: