30 lines
764 B
Go
30 lines
764 B
Go
//
|
|
// Copyright (C) 2024 veypi <i@veypi.com>
|
|
// 2025-02-27 19:32:09
|
|
// Distributed under terms of the MIT license.
|
|
//
|
|
|
|
package main
|
|
|
|
import "app/cfg"
|
|
|
|
var cmdDB = CMD.SubCommand("db", "database operations")
|
|
var cmdMigrate = cmdDB.SubCommand("migrate", "migrate database")
|
|
|
|
func init() {
|
|
cmdMigrate.Command = func() error {
|
|
// create table without constraints
|
|
cfg.DB().DisableForeignKeyConstraintWhenMigrating = true
|
|
err := cfg.DB().AutoMigrate(cfg.ObjList...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// create constraints
|
|
cfg.DB().DisableForeignKeyConstraintWhenMigrating = false
|
|
return cfg.DB().AutoMigrate(cfg.ObjList...)
|
|
}
|
|
cmdDB.SubCommand("drop", "drop database").Command = func() error {
|
|
return cfg.DB().Migrator().DropTable(cfg.ObjList...)
|
|
}
|
|
}
|