blob: fdbddfe4b01bd28855c4f2f8a8b2fcacdb0e8390 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package commands
import (
"context"
"flag"
"fmt"
"os"
"github.com/eugenetriguba/bolt/internal/db"
"github.com/google/subcommands"
)
type MigrateCmd struct{}
func (*MigrateCmd) Name() string { return "migrate" }
func (*MigrateCmd) Synopsis() string { return "Migrate the database to the latest migration." }
func (*MigrateCmd) Usage() string {
return `migrate:
Migrate the database to the latest migration.
`
}
func (m *MigrateCmd) SetFlags(f *flag.FlagSet) {}
func (m *MigrateCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
db, err := db.Connect()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return subcommands.ExitFailure
}
defer db.Close()
sqlStatement := `
CREATE TABLE IF NOT EXISTS applied_migration(
version CHARACTER(32) PRIMARY KEY NOT NULL
);
`
_, err = db.Exec(sqlStatement)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return subcommands.ExitFailure
}
return subcommands.ExitSuccess
}
|