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
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -17,6 +18,9 @@ import (
|
|||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
var embeddedMigrations embed.FS
|
||||
|
||||
func Migration(db *gorm.DB) error {
|
||||
if err := db.AutoMigrate(uModel.User{}, chModel.Chore{},
|
||||
chModel.ChoreHistory{},
|
||||
|
@ -41,8 +45,9 @@ func Migration(db *gorm.DB) error {
|
|||
}
|
||||
|
||||
func MigrationScripts(gormDB *gorm.DB, cfg *config.Config) error {
|
||||
migrations := &migrate.FileMigrationSource{
|
||||
Dir: migrationDir(),
|
||||
migrations := &migrate.EmbedFileSystemMigrationSource{
|
||||
FileSystem: embeddedMigrations,
|
||||
Root: "migrations",
|
||||
}
|
||||
|
||||
path := os.Getenv("DT_SQLITE_PATH")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue