feature: Add SQL for migration
This commit is contained in:
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
DELETE
|
||||||
|
FROM migration.functions
|
||||||
|
WHERE filename = :filename;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
DELETE
|
||||||
|
FROM migration.history
|
||||||
|
WHERE filename = :filename;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
SELECT json_object_agg(filename, f)
|
||||||
|
FROM migration.functions f;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
SELECT json_object_agg(filename, f)
|
||||||
|
FROM migration.functions f;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
SELECT nextval('migration.version_seq');
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
INSERT INTO migration.functions (filename, definition, up, down, version)
|
||||||
|
VALUES (:filename, :definition, :up, :down, :version);
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
INSERT INTO migration.history (filename, up, down, version)
|
||||||
|
VALUES (:filename, :up, :down, :version);
|
||||||
Reference in New Issue
Block a user