feature: Add SQL for migration

This commit is contained in:
2019-07-01 16:58:19 +02:00
parent 74c9543b6d
commit 0a6c38661a
9 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
CREATE SCHEMA IF NOT EXISTS migration;
CREATE TABLE IF NOT EXISTS migration.functions
(
filename text PRIMARY KEY,
definition text NOT NULL,
executed_at timestamp DEFAULT now() NOT NULL,
up text NOT NULL,
down text NOT NULL,
version int NOT NULL
);
CREATE SEQUENCE IF NOT EXISTS migration.version_seq;

View File

@@ -0,0 +1,12 @@
CREATE SCHEMA IF NOT EXISTS migration;
CREATE TABLE IF NOT EXISTS migration.history
(
filename text PRIMARY KEY,
executed_at timestamp DEFAULT now() NOT NULL,
up text NOT NULL,
down text NOT NULL,
version int NOT NULL
);
CREATE SEQUENCE IF NOT EXISTS migration.version_seq;

View File

@@ -0,0 +1,3 @@
DELETE
FROM migration.functions
WHERE filename = :filename;

View File

@@ -0,0 +1,3 @@
DELETE
FROM migration.history
WHERE filename = :filename;

View File

@@ -0,0 +1,2 @@
SELECT json_object_agg(filename, f)
FROM migration.functions f;

View File

@@ -0,0 +1,2 @@
SELECT json_object_agg(filename, f)
FROM migration.functions f;

View File

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

View File

@@ -0,0 +1,2 @@
INSERT INTO migration.functions (filename, definition, up, down, version)
VALUES (:filename, :definition, :up, :down, :version);

View File

@@ -0,0 +1,2 @@
INSERT INTO migration.history (filename, up, down, version)
VALUES (:filename, :up, :down, :version);