mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add position column in labels table
This commit is contained in:
parent
5e2e2a2151
commit
5e8508e025
2 changed files with 34 additions and 0 deletions
25
packages/db/migrations/0090.do.add_position_to_labels.sql
Executable file
25
packages/db/migrations/0090.do.add_position_to_labels.sql
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
-- Type: DO
|
||||
-- Name: add_position_to_labels
|
||||
-- Description: Add position column to labels table
|
||||
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.labels ADD COLUMN position INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
WITH positions AS (
|
||||
SELECT
|
||||
id, row_number() OVER (PARTITION BY user_id ORDER BY name) as row_num
|
||||
FROM
|
||||
omnivore.labels
|
||||
) UPDATE
|
||||
omnivore.labels
|
||||
SET
|
||||
position = positions.row_num
|
||||
FROM
|
||||
positions
|
||||
WHERE
|
||||
omnivore.labels.id = positions.id;
|
||||
|
||||
ALTER TABLE omnivore.labels ADD constraint labels_position_user_id_unique UNIQUE(user_id, position);
|
||||
|
||||
COMMIT;
|
||||
9
packages/db/migrations/0090.undo.add_position_to_labels.sql
Executable file
9
packages/db/migrations/0090.undo.add_position_to_labels.sql
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
-- Type: UNDO
|
||||
-- Name: add_position_to_labels
|
||||
-- Description: Add position column to labels table
|
||||
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.labels DROP COLUMN IF EXISTS position;
|
||||
|
||||
COMMIT;
|
||||
Loading…
Reference in a new issue