Skip to content

Commit 3dd9e78

Browse files
committed
fix: make migration idempotent
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent 670089b commit 3dd9e78

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
ALTER TABLE "storage"."objects"
2-
ADD CONSTRAINT objects_name_check
3-
CHECK (
4-
name !~ E'[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]'
5-
AND POSITION(U&'\FFFE' IN name) = 0
6-
AND POSITION(U&'\FFFF' IN name) = 0
7-
);
1+
DO $$
2+
BEGIN
3+
IF NOT EXISTS (
4+
SELECT 1
5+
FROM pg_constraint c
6+
JOIN pg_class t ON t.oid = c.conrelid
7+
JOIN pg_namespace n ON n.oid = t.relnamespace
8+
WHERE c.conname = 'objects_name_check'
9+
AND n.nspname = 'storage'
10+
AND t.relname = 'objects'
11+
) THEN
12+
ALTER TABLE "storage"."objects"
13+
ADD CONSTRAINT objects_name_check
14+
CHECK (
15+
name !~ E'[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]'
16+
AND POSITION(U&'\FFFE' IN name) = 0
17+
AND POSITION(U&'\FFFF' IN name) = 0
18+
);
19+
END IF;
20+
END
21+
$$;

src/scripts/migrations-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function main() {
3939

4040
const template = `export const DBMigration = {
4141
${migrationsEnum.join('\n')}
42-
}
42+
} as const
4343
`
4444

4545
const destinationPath = path.resolve(

0 commit comments

Comments
 (0)