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)
	}

}
