Add migrations

This commit is contained in:
2020-10-08 14:08:50 +02:00
parent 98d8c2e5d8
commit 7ee52c758b
10 changed files with 779 additions and 141 deletions

View File

@@ -0,0 +1,3 @@
--
-- DROP/Reverse everything here
--

View File

@@ -0,0 +1,46 @@
CREATE SEQUENCE public.persons_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE IF NOT EXISTS public.persons
(
id integer DEFAULT nextval('public.persons_id_seq'::regclass) NOT NULL,
name character varying(100) NOT NULL,
PRIMARY KEY (id)
);
CREATE SEQUENCE public.gamedata_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE IF NOT EXISTS public.gamedata
(
id integer DEFAULT nextval('public.gamedata_id_seq'::regclass) NOT NULL,
created_at timestamp without time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE SEQUENCE public.washlist_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE IF NOT EXISTS public.washlist
(
id integer DEFAULT nextval('public.washlist_id_seq'::regclass) NOT NULL,
personid integer NOT NULL,
gamedataid integer NOT NULL,
washed boolean NOT NULL,
PRIMARY KEY (id)
);

View File

@@ -0,0 +1,24 @@
package migrations
import (
"fmt"
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
"log"
"trikotwaschliste/models"
)
func RunMigration(config models.Config) {
m, err := migrate.New(
"file://database/migrations",
"postgres://"+config.DB_USER+":"+config.DB_PASSWORD+"@"+config.DB_HOST+":"+
fmt.Sprint(config.DB_PORT)+"/"+config.DB_DATABASE+"?sslmode=disable")
if err != nil {
log.Fatal(err)
}
if err := m.Up(); err != nil {
log.Println(err)
}
}