Add migrations
This commit is contained in:
3
database/migrations/20100830201_init.down.psql
Normal file
3
database/migrations/20100830201_init.down.psql
Normal file
@@ -0,0 +1,3 @@
|
||||
--
|
||||
-- DROP/Reverse everything here
|
||||
--
|
46
database/migrations/20100830201_init.up.psql
Normal file
46
database/migrations/20100830201_init.up.psql
Normal 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)
|
||||
);
|
24
database/migrations/migrationrunner.go
Normal file
24
database/migrations/migrationrunner.go
Normal 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)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user