53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
|
/*
|
||
|
Package cmd
|
||
|
Copyright © 2024 Shane C. <shane@scaffoe.com>
|
||
|
*/
|
||
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/jackc/pgx/v5/pgxpool"
|
||
|
"github.com/jackc/pgx/v5/stdlib"
|
||
|
"github.com/uptrace/bun"
|
||
|
"github.com/uptrace/bun/dialect/pgdialect"
|
||
|
"github.com/uptrace/bun/migrate"
|
||
|
"log"
|
||
|
"omnibill.net/omnibill/migrations"
|
||
|
"omnibill.net/omnibill/shared"
|
||
|
|
||
|
"github.com/spf13/cobra"
|
||
|
)
|
||
|
|
||
|
// unlockCmd represents the unlock command
|
||
|
var unlockCmd = &cobra.Command{
|
||
|
Use: "unlock",
|
||
|
Short: "Unlocks DB migrations",
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
dsn := shared.GetPostgresURI()
|
||
|
|
||
|
config, err := pgxpool.ParseConfig(dsn)
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
pool, err := pgxpool.NewWithConfig(context.Background(), config)
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
|
||
|
sqldb := stdlib.OpenDBFromPool(pool)
|
||
|
db := bun.NewDB(sqldb, pgdialect.New())
|
||
|
|
||
|
migrator := migrate.NewMigrator(db, migrations.Migrations)
|
||
|
ctx := context.Background()
|
||
|
|
||
|
err = migrator.Unlock(ctx)
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
},
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
migrateCmd.AddCommand(unlockCmd)
|
||
|
}
|