Evan Reichard
e68dfc445f
All checks were successful
continuous-integration/drone/push Build is passing
39 lines
739 B
Go
39 lines
739 B
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/pressly/goose/v3"
|
|
)
|
|
|
|
func init() {
|
|
goose.AddMigrationContext(upImportBasepath, downImportBasepath)
|
|
}
|
|
|
|
func upImportBasepath(ctx context.Context, tx *sql.Tx) error {
|
|
// Determine if we have a new DB or not
|
|
isNew := ctx.Value("isNew").(bool)
|
|
if isNew {
|
|
return nil
|
|
}
|
|
|
|
// Add basepath column
|
|
_, err := tx.Exec(`ALTER TABLE documents ADD COLUMN basepath TEXT;`)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// This code is executed when the migration is applied.
|
|
return nil
|
|
}
|
|
|
|
func downImportBasepath(ctx context.Context, tx *sql.Tx) error {
|
|
// Drop basepath column
|
|
_, err := tx.Exec("ALTER documents DROP COLUMN basepath;")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|