fix: functions migrations

This commit is contained in:
2019-08-02 20:39:30 +02:00
parent 56a141a34c
commit 88d581c529
7 changed files with 54 additions and 8 deletions

View File

@@ -9,5 +9,3 @@ CREATE TABLE IF NOT EXISTS migration.functions
down text NOT NULL,
version int NOT NULL
);
CREATE SEQUENCE IF NOT EXISTS migration.version_seq;

View File

@@ -1 +0,0 @@
SELECT nextval('migration.version_seq');

View File

@@ -1,3 +1,7 @@
INSERT INTO migration.functions as f (filename, definition, executed_at, up, down, version)
VALUES (?, ?, now(), ?, ?, ?)
VALUES (?, ?, now(), ?, ?, (
select coalesce(max(version), 0)+1
from migration.functions f2
where filename = f2.filename
))
RETURNING to_json(f);

View File

@@ -1,3 +1,7 @@
INSERT INTO migration.history as h (filename, executed_at, up, down, version)
VALUES (?, now(), ?, ?, nextval('migration.version_seq'))
VALUES (?, now(), ?, ?, (
select coalesce(max(version), 0)+1
from migration.history f2
where filename = f2.filename
))
RETURNING to_json(h);