Remove unused migrationDir function and related imports
Support Migration using sql ( for future use)
This commit is contained in:
commit
98038dcf23
4 changed files with 132 additions and 79 deletions
|
@ -1,10 +1,9 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"donetick.com/core/config"
|
||||
chModel "donetick.com/core/internal/chore/model"
|
||||
|
@ -17,6 +16,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 +43,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")
|
||||
|
@ -62,11 +65,3 @@ func MigrationScripts(gormDB *gorm.DB, cfg *config.Config) error {
|
|||
fmt.Printf("Applied %d migrations!\n", n)
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrationDir() string {
|
||||
_, filename, _, ok := runtime.Caller(1)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(filepath.Dir(filename), "../../migrations")
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
-- +migrate Up
|
||||
-- nothing here just to include in he embeded sql :)
|
Loading…
Add table
Add a link
Reference in a new issue