use embed File System for Migration script
This commit is contained in:
parent
cb3a321b4f
commit
f49fc848e4
1 changed files with 7 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -17,6 +18,9 @@ import (
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed migrations/*.sql
|
||||||
|
var embeddedMigrations embed.FS
|
||||||
|
|
||||||
func Migration(db *gorm.DB) error {
|
func Migration(db *gorm.DB) error {
|
||||||
if err := db.AutoMigrate(uModel.User{}, chModel.Chore{},
|
if err := db.AutoMigrate(uModel.User{}, chModel.Chore{},
|
||||||
chModel.ChoreHistory{},
|
chModel.ChoreHistory{},
|
||||||
|
@ -41,8 +45,9 @@ func Migration(db *gorm.DB) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MigrationScripts(gormDB *gorm.DB, cfg *config.Config) error {
|
func MigrationScripts(gormDB *gorm.DB, cfg *config.Config) error {
|
||||||
migrations := &migrate.FileMigrationSource{
|
migrations := &migrate.EmbedFileSystemMigrationSource{
|
||||||
Dir: migrationDir(),
|
FileSystem: embeddedMigrations,
|
||||||
|
Root: "migrations",
|
||||||
}
|
}
|
||||||
|
|
||||||
path := os.Getenv("DT_SQLITE_PATH")
|
path := os.Getenv("DT_SQLITE_PATH")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue