feat: embed schema migrations in binary
This commit is contained in:
parent
e52620a9e2
commit
8eb41ab8a8
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,5 +3,6 @@ dist/
|
||||
uploads/*
|
||||
!uploads/.keep
|
||||
internal/frontend/frontend_generated.go
|
||||
internal/migrations/migrations_generated.go
|
||||
citadel
|
||||
conf/app.toml
|
||||
|
@ -7,8 +7,10 @@ import (
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
"github.com/golang-migrate/migrate/v4/source/httpfs"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/jordanknott/project-citadel/api/internal/config"
|
||||
"github.com/jordanknott/project-citadel/api/internal/migrations"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -50,9 +52,12 @@ func newMigrateCmd() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := migrate.NewWithDatabaseInstance(
|
||||
"file://migrations",
|
||||
"postgres", driver)
|
||||
|
||||
src, err := httpfs.New(migrations.Migrations, "./")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := migrate.NewWithInstance("httpfs", src, "postgres", driver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
18
magefile.go
18
magefile.go
@ -31,6 +31,22 @@ func (Frontend) Build() error {
|
||||
|
||||
type Backend mg.Namespace
|
||||
|
||||
func (Backend) GenMigrations() error {
|
||||
if _, err := os.Stat("internal/migrations"); os.IsNotExist(err) {
|
||||
os.Mkdir("internal/migrations/", 0755)
|
||||
}
|
||||
var fs http.FileSystem = http.Dir("migrations")
|
||||
err := vfsgen.Generate(fs, vfsgen.Options{
|
||||
Filename: "internal/migrations/migrations_generated.go",
|
||||
PackageName: "migrations",
|
||||
VariableName: "Migrations",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (Backend) GenFrontend() error {
|
||||
if _, err := os.Stat("internal/frontend/"); os.IsNotExist(err) {
|
||||
os.Mkdir("internal/frontend/", 0755)
|
||||
@ -83,7 +99,7 @@ func Install() {
|
||||
}
|
||||
|
||||
func Build() {
|
||||
mg.SerialDeps(Frontend.Build, Backend.GenFrontend, Backend.Build)
|
||||
mg.SerialDeps(Frontend.Build, Backend.GenMigrations, Backend.GenFrontend, Backend.Build)
|
||||
}
|
||||
|
||||
type Docker mg.Namespace
|
||||
|
Loading…
Reference in New Issue
Block a user