Better migration locking behaviour
This commit is contained in:
@@ -2,4 +2,12 @@ CREATE TABLE IF NOT EXISTS migrations (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name text UNIQUE NOT NULL,
|
||||
applied_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS migrations_lock (
|
||||
id integer PRIMARY KEY,
|
||||
is_locked boolean NOT NULL DEFAULT false
|
||||
);
|
||||
|
||||
INSERT INTO migrations_lock (id, is_locked) VALUES (1, false)
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
3
sql/migrations/lock.sql
Normal file
3
sql/migrations/lock.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
WITH rows as (
|
||||
UPDATE migrations_lock SET is_locked = true WHERE is_locked = false RETURNING 1
|
||||
) SELECT COUNT(*) FROM rows;
|
||||
1
sql/migrations/unlock.sql
Normal file
1
sql/migrations/unlock.sql
Normal file
@@ -0,0 +1 @@
|
||||
UPDATE migrations_lock SET is_locked = false WHERE is_locked = true;
|
||||
Reference in New Issue
Block a user