From 13ea96e4e5df79c4a6bc8f1a4ccc6c7836092bb0 Mon Sep 17 00:00:00 2001 From: Vaniog Date: Thu, 6 Jun 2024 19:12:13 +0300 Subject: [PATCH] init --- .gitignore | 6 + Makefile | 2 + app/app.go | 22 ++++ app/build/build_mysql.go | 8 ++ app/build/build_postgres.go | 5 + app/build/build_sqlite.go | 8 ++ app/config/config.go | 97 ++++++++++++++++ app/config_keymap.go | 37 ++++++ app/config_model.go | 124 ++++++++++++++++++++ app/create_migration_keymap.go | 27 +++++ app/create_migration_model.go | 113 ++++++++++++++++++ app/goto_keymap.go | 32 +++++ app/goto_model.go | 125 ++++++++++++++++++++ app/line_logger.go | 44 +++++++ app/log_model.go | 49 ++++++++ app/migrate_keymap.go | 47 ++++++++ app/migrate_model.go | 180 +++++++++++++++++++++++++++++ go.mod | 61 ++++++++++ go.sum | 205 +++++++++++++++++++++++++++++++++ main.go | 13 +++ 20 files changed, 1205 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 app/app.go create mode 100644 app/build/build_mysql.go create mode 100644 app/build/build_postgres.go create mode 100644 app/build/build_sqlite.go create mode 100644 app/config/config.go create mode 100644 app/config_keymap.go create mode 100644 app/config_model.go create mode 100644 app/create_migration_keymap.go create mode 100644 app/create_migration_model.go create mode 100644 app/goto_keymap.go create mode 100644 app/goto_model.go create mode 100644 app/line_logger.go create mode 100644 app/log_model.go create mode 100644 app/migrate_keymap.go create mode 100644 app/migrate_model.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bfca9ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.lazymigrate +migrations +docker-compose.yml +.idea +.env +app.db \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..00f72ac --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +build-full: + go build -tags "postgres mysql sqlite" diff --git a/app/app.go b/app/app.go new file mode 100644 index 0000000..04701df --- /dev/null +++ b/app/app.go @@ -0,0 +1,22 @@ +package app + +import ( + "github.com/Vaniog/lazymigrate/app/config" + tea "github.com/charmbracelet/bubbletea" +) + +type App struct { + tea *tea.Program +} + +func NewApp() *App { + model := newMigrateModel(config.Source, config.URL) + return &App{ + tea.NewProgram(model), + } +} + +func (a *App) Run() error { + _, err := a.tea.Run() + return err +} diff --git a/app/build/build_mysql.go b/app/build/build_mysql.go new file mode 100644 index 0000000..73f6082 --- /dev/null +++ b/app/build/build_mysql.go @@ -0,0 +1,8 @@ +//go:build mysql +// +build mysql + +package build + +import ( + _ "github.com/golang-migrate/migrate/v4/database/mysql" +) diff --git a/app/build/build_postgres.go b/app/build/build_postgres.go new file mode 100644 index 0000000..4bd3267 --- /dev/null +++ b/app/build/build_postgres.go @@ -0,0 +1,5 @@ +package build + +import ( + _ "github.com/golang-migrate/migrate/v4/database/postgres" +) diff --git a/app/build/build_sqlite.go b/app/build/build_sqlite.go new file mode 100644 index 0000000..2ca9770 --- /dev/null +++ b/app/build/build_sqlite.go @@ -0,0 +1,8 @@ +//go:build sqlite +// +build sqlite + +package build + +import ( + _ "github.com/golang-migrate/migrate/v4/database/sqlite" +) diff --git a/app/config/config.go b/app/config/config.go new file mode 100644 index 0000000..4a19e50 --- /dev/null +++ b/app/config/config.go @@ -0,0 +1,97 @@ +package config + +import "C" +import ( + "fmt" + "github.com/joho/godotenv" + "github.com/kelseyhightower/envconfig" + "os" +) + +var URL string +var Source = "migrations" + +func loadEnv() { + err := godotenv.Load(".lazymigrate") + if err == nil { + return + } + _ = godotenv.Load(".env") +} + +func init() { + loadEnv() + loadSource() + if loadDirect() { + return + } + if err := loadPostgres(); err == nil { + return + } + if err := loadMySQL(); err == nil { + return + } +} + +func loadSource() { + source, ok := os.LookupEnv("LAZYMIGRATE_SOURCE") + if ok { + Source = source + } +} + +func loadDirect() bool { + url, ok := os.LookupEnv("LAZYMIGRATE_URL") + if ok { + URL = url + } + return ok +} + +func loadMySQL() error { + var mysql struct { + User string `envconfig:"USER" required:"true"` + Password string `envconfig:"PASSWORD" required:"true"` + Host string `envconfig:"HOST" default:"localhost"` + Port uint16 `envconfig:"PORT" default:"3306"` + Database string `envconfig:"DATABASE" required:"true"` + } + + if err := envconfig.Process("MYSQL", &mysql); err != nil { + return err + } + + URL = fmt.Sprintf( + "mysql://%s:%s@tcp(%s:%d)/%s?query", + mysql.User, + mysql.Password, + mysql.Host, + mysql.Port, + mysql.Database, + ) + return nil +} + +func loadPostgres() error { + var pg struct { + User string `envconfig:"USER" required:"true"` + Password string `envconfig:"PASSWORD" required:"true"` + Host string `envconfig:"HOST" default:"localhost"` + Port uint16 `envconfig:"PORT" default:"5432"` + Database string `envconfig:"DB" required:"true"` + } + + if err := envconfig.Process("POSTGRES", &pg); err != nil { + return err + } + + URL = fmt.Sprintf( + "postgres://%s:%s@%s:%d/%s?sslmode=disable", + pg.User, + pg.Password, + pg.Host, + pg.Port, + pg.Database, + ) + return nil +} diff --git a/app/config_keymap.go b/app/config_keymap.go new file mode 100644 index 0000000..8db617a --- /dev/null +++ b/app/config_keymap.go @@ -0,0 +1,37 @@ +package app + +import "github.com/charmbracelet/bubbles/key" + +type configKeymap struct { + Apply key.Binding + Save key.Binding + Next key.Binding + Exit key.Binding +} + +var defaultConfigKeymap = configKeymap{ + Apply: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "apply"), + ), + Save: key.NewBinding( + key.WithKeys("ctrl+s"), + key.WithHelp("ctrl+s", "save to .lazymigrate"), + ), + Next: key.NewBinding( + key.WithKeys("tab", "up", "down"), + key.WithHelp("tab/↑/↓", "edit next"), + ), + Exit: key.NewBinding( + key.WithKeys("ctrl+c"), + key.WithHelp("ctrl+c", "exit"), + ), +} + +func (m configKeymap) ShortHelp() []key.Binding { + return []key.Binding{m.Exit, m.Next, m.Apply, m.Save} +} + +func (m configKeymap) FullHelp() [][]key.Binding { + return [][]key.Binding{m.ShortHelp()} +} diff --git a/app/config_model.go b/app/config_model.go new file mode 100644 index 0000000..381da24 --- /dev/null +++ b/app/config_model.go @@ -0,0 +1,124 @@ +package app + +import ( + "fmt" + "github.com/charmbracelet/bubbles/key" + "github.com/charmbracelet/lipgloss" + "os" + + "github.com/charmbracelet/bubbles/help" + "github.com/charmbracelet/bubbles/textinput" + tea "github.com/charmbracelet/bubbletea" +) + +type configModel struct { + source textinput.Model + database textinput.Model + + // which field is edit now + edit string + + help help.Model + keymap configKeymap + + // to return + prevM migrateModel +} + +func newConfigModel(mm migrateModel) configModel { + cm := configModel{ + source: textinput.New(), + database: textinput.New(), + help: help.New(), + keymap: defaultConfigKeymap, + } + + cm.source.Prompt = " Source " + cm.source.Placeholder = "path" + cm.source.SetValue(mm.sourceFile) + cm.database.Prompt = " Database " + cm.database.Placeholder = "driver://..." + cm.database.SetValue(mm.databaseUrl) + cm.database.Focus() + + cm.edit = "database" + + cm.prevM = mm + + return cm +} + +func (cm configModel) Init() tea.Cmd { + return textinput.Blink +} + +func (cm configModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + var cmds []tea.Cmd + + switch msg := msg.(type) { + case tea.KeyMsg: + switch { + case key.Matches(msg, cm.keymap.Next): + if cm.edit == "source" { + cm.edit = "database" + cm.source.Blur() + cm.database.Focus() + } else { + cm.edit = "source" + cm.database.Blur() + cm.source.Focus() + } + return cm, nil + case key.Matches(msg, cm.keymap.Apply): + mm := newMigrateModel(cm.source.Value(), cm.database.Value()) + return mm, mm.Init() + case key.Matches(msg, cm.keymap.Save): + cm.save() + mm := newMigrateModel(cm.source.Value(), cm.database.Value()) + return mm, mm.Init() + case key.Matches(msg, cm.keymap.Exit): + return cm.prevM, nil + } + + case tea.WindowSizeMsg: + cm.help.Width = msg.Width + } + + if cm.edit == "source" { + var cmd tea.Cmd + cm.source, cmd = cm.source.Update(msg) + cmds = append(cmds, cmd) + } else { + var cmd tea.Cmd + cm.database, cmd = cm.database.Update(msg) + cmds = append(cmds, cmd) + } + + return cm, tea.Batch(cmds...) +} + +func (cm configModel) save() { + _ = os.Remove(".lazymigrate") + f, err := os.Create(".lazymigrate") + if err != nil { + return + } + cfg := fmt.Sprintf( + "LAZYMIGRATE_URL=%s\nLAZYMIGRATE_SOURCE=%s\n", + cm.database.Value(), + cm.source.Value(), + ) + _, _ = f.Write([]byte(cfg)) +} + +func (cm configModel) View() string { + + return fmt.Sprintf(lipgloss.JoinVertical( + 0, + ">> Edit Config", + cm.database.View(), + cm.source.View(), + "", + cm.help.View(cm.keymap), + )) +} diff --git a/app/create_migration_keymap.go b/app/create_migration_keymap.go new file mode 100644 index 0000000..1540bd8 --- /dev/null +++ b/app/create_migration_keymap.go @@ -0,0 +1,27 @@ +package app + +import "github.com/charmbracelet/bubbles/key" + +type createMigrationKeymap struct { + Save key.Binding + Exit key.Binding +} + +var defaultCreateMigrationKeymap = createMigrationKeymap{ + Save: key.NewBinding( + key.WithKeys("ctrl+s", "enter"), + key.WithHelp("ctrl+s/enter", "save"), + ), + Exit: key.NewBinding( + key.WithKeys("ctrl+c"), + key.WithHelp("ctrl+c", "exit"), + ), +} + +func (m createMigrationKeymap) ShortHelp() []key.Binding { + return []key.Binding{m.Exit, m.Save} +} + +func (m createMigrationKeymap) FullHelp() [][]key.Binding { + return [][]key.Binding{m.ShortHelp()} +} diff --git a/app/create_migration_model.go b/app/create_migration_model.go new file mode 100644 index 0000000..912c4bd --- /dev/null +++ b/app/create_migration_model.go @@ -0,0 +1,113 @@ +package app + +import ( + "fmt" + "github.com/charmbracelet/bubbles/help" + "github.com/charmbracelet/bubbles/key" + "github.com/charmbracelet/bubbles/textinput" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "os" + "path" + "time" +) + +type createMigrationModel struct { + name textinput.Model + status string + + // prevM for returning to state + prevM migrateModel + + help help.Model + keymap createMigrationKeymap +} + +func newCreateMigrationModel(mm migrateModel) createMigrationModel { + cm := createMigrationModel{ + prevM: mm, + keymap: defaultCreateMigrationKeymap, + help: help.New(), + } + + cm.name = textinput.New() + cm.name.Prompt = "> " + cm.name.Placeholder = "create_table" + cm.name.Focus() + return cm +} + +func (cmm createMigrationModel) Init() tea.Cmd { + return textinput.Blink +} + +func (cmm createMigrationModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + switch { + case key.Matches(msg, cmm.keymap.Save): + if cmm.status == "" { + // input stage + err := cmm.create() + if err != nil { + cmm.status = fmt.Sprintf("error: %s", err) + } else { + cmm.status = "created!" + } + cmm.name.Blur() + return cmm, nil + } else { + // status stage + return cmm.prevM, nil + } + case key.Matches(msg, cmm.keymap.Exit): + return cmm.prevM, nil + } + } + + var cmd tea.Cmd + cmm.name, cmd = cmm.name.Update(msg) + return cmm, cmd +} + +func (cmm createMigrationModel) View() string { + view := lipgloss.JoinVertical( + 0, + "Name of new migration:\n", + cmm.name.View(), + ) + if cmm.status != "" { + view = lipgloss.JoinVertical( + 0, + fmt.Sprintf("[status]: %s", cmm.status), + ) + } + + view += fmt.Sprintf("\n\n%s", cmm.help.View(cmm.keymap)) + + return view +} + +func (cmm createMigrationModel) create() error { + name := fmt.Sprintf( + "%s_%s", + cmm.formatTime(time.Now().UTC()), + cmm.name.Value(), + ) + if err := createFile(path.Join(cmm.prevM.sourceFile, fmt.Sprintf("%s.up.sql", name))); err != nil { + return err + } + if err := createFile(path.Join(cmm.prevM.sourceFile, fmt.Sprintf("%s.down.sql", name))); err != nil { + return err + } + return nil +} + +func (cmm createMigrationModel) formatTime(t time.Time) string { + return t.Format("200601021504") +} + +func createFile(p string) error { + _, err := os.Create(p) + return err +} diff --git a/app/goto_keymap.go b/app/goto_keymap.go new file mode 100644 index 0000000..80f1b06 --- /dev/null +++ b/app/goto_keymap.go @@ -0,0 +1,32 @@ +package app + +import "github.com/charmbracelet/bubbles/key" + +type gotoKeymap struct { + Apply key.Binding + Exit key.Binding +} + +var defaultGotoKeymap = gotoKeymap{ + Apply: key.NewBinding( + key.WithKeys("enter"), + key.WithHelp("enter", "apply"), + ), + Exit: key.NewBinding( + key.WithKeys("ctrl+c"), + key.WithHelp("ctrl+c", "exit"), + ), +} + +func (m gotoKeymap) ShortHelp() []key.Binding { + return []key.Binding{ + m.Exit, + key.NewBinding(key.WithKeys("up", "down"), key.WithHelp("↑/↓", "scroll")), + key.NewBinding(key.WithKeys("tab"), key.WithHelp("tab", "complete")), + m.Apply, + } +} + +func (m gotoKeymap) FullHelp() [][]key.Binding { + return [][]key.Binding{m.ShortHelp()} +} diff --git a/app/goto_model.go b/app/goto_model.go new file mode 100644 index 0000000..c7a4100 --- /dev/null +++ b/app/goto_model.go @@ -0,0 +1,125 @@ +package app + +import ( + "github.com/Vaniog/lazymigrate/app/config" + "github.com/charmbracelet/bubbles/help" + "github.com/charmbracelet/bubbles/key" + "github.com/charmbracelet/bubbles/textinput" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "os" + "path/filepath" + "strconv" + "strings" +) + +type gotoModel struct { + migration textinput.Model + migrations []migrationDto + + help help.Model + keymap gotoKeymap + + prevM migrateModel +} + +type migrationDto struct { + version uint + name string +} + +func newGotoModel(prevM migrateModel) gotoModel { + gm := gotoModel{ + migration: textinput.New(), + help: help.New(), + keymap: defaultGotoKeymap, + prevM: prevM, + } + + gm.migration.Focus() + gm.migration.Placeholder = "" + gm.migration.Prompt = "> " + + var suggestions []string + gm.migrations = availableMigrations() + for _, m := range gm.migrations { + suggestions = append(suggestions, m.name, strconv.Itoa(int(m.version))) + } + + gm.migration.SetSuggestions(suggestions) + gm.migration.ShowSuggestions = true + return gm +} + +func (gm gotoModel) Init() tea.Cmd { + return nil +} + +func (gm gotoModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + switch { + case key.Matches(msg, gm.keymap.Exit): + return gm.prevM, nil + case key.Matches(msg, gm.keymap.Apply): + if v, err := strconv.ParseInt(gm.migration.Value(), 10, 64); err == nil { + return gm.prevM, func() tea.Msg { + return gotoMigrationMsg{uint(v)} + } + } + + for _, m := range gm.migrations { + if m.name == gm.migration.Value() { + return gm.prevM, func() tea.Msg { + return gotoMigrationMsg{m.version} + } + } + } + + return gm.prevM, nil + } + } + + newMigration, cmd := gm.migration.Update(msg) + gm.migration = newMigration + return gm, cmd +} + +func (gm gotoModel) View() string { + return lipgloss.JoinVertical( + 0, + "Migration name or version\n", + gm.migration.View(), + "\n", + gm.help.View(gm.keymap), + ) +} + +func availableMigrations() []migrationDto { + var ms []migrationDto + _ = filepath.WalkDir(config.Source, func(path string, d os.DirEntry, err error) error { + if err != nil { + return err + } + + if !d.IsDir() && strings.HasSuffix(d.Name(), ".up.sql") { + parts := strings.Split(d.Name(), "_") + if len(parts) > 1 { + versionStr := parts[0] + version, err := strconv.ParseUint(versionStr, 10, 64) + if err != nil { + return nil + } + + name := strings.Split(d.Name()[len(versionStr)+1:len(d.Name())], ".")[0] + ms = append(ms, migrationDto{ + version: uint(version), + name: name, + }) + } + } + + return nil + }) + return ms +} diff --git a/app/line_logger.go b/app/line_logger.go new file mode 100644 index 0000000..03c4ba2 --- /dev/null +++ b/app/line_logger.go @@ -0,0 +1,44 @@ +package app + +import ( + "fmt" + "strings" + "sync" + "time" +) + +type log struct { + time time.Time + line string +} + +type lineLogger struct { + logs []log + logsLock sync.Mutex + maxSize int +} + +func newLineLogger(maxSize int) *lineLogger { + return &lineLogger{ + logs: nil, + logsLock: sync.Mutex{}, + maxSize: maxSize, + } +} + +func (ll *lineLogger) Printf(format string, v ...interface{}) { + line := fmt.Sprintf(format, v...) + + line = strings.Split(line, "\n")[0] + ll.logsLock.Lock() + defer ll.logsLock.Unlock() + ll.logs = append(ll.logs, log{time.Now(), line}) + if len(ll.logs) > ll.maxSize { + ll.logs = ll.logs[1:] + } +} + +// Verbose is for implementing migrate.Logger +func (_ *lineLogger) Verbose() bool { + return false +} diff --git a/app/log_model.go b/app/log_model.go new file mode 100644 index 0000000..b1db1f4 --- /dev/null +++ b/app/log_model.go @@ -0,0 +1,49 @@ +package app + +import ( + "fmt" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "time" +) + +type logModel struct { + lineLogger *lineLogger + logsLifetime time.Duration +} + +type logModelTickMessage struct{} + +var defaultLogModel = logModel{ + lineLogger: newLineLogger(5), + logsLifetime: 2000 * time.Millisecond, +} + +func (lm logModel) active() bool { + logs := lm.lineLogger.logs + if len(logs) == 0 { + return false + } + return logs[len(logs)-1].time.Add(lm.logsLifetime).After(time.Now()) +} + +func (lm logModel) Init() tea.Cmd { + return nil +} + +func (lm logModel) Update(_ tea.Msg) (tea.Model, tea.Cmd) { + return lm, nil +} + +func (lm logModel) View() string { + view := "" + lm.lineLogger.logsLock.Lock() + defer lm.lineLogger.logsLock.Unlock() + + timeStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("6")) + for _, log := range lm.lineLogger.logs { + timeStr := timeStyle.Render(log.time.Format("15:04:05")) + view += fmt.Sprintf(" > %s %s\n", timeStr, log.line) + } + return view +} diff --git a/app/migrate_keymap.go b/app/migrate_keymap.go new file mode 100644 index 0000000..828f8d8 --- /dev/null +++ b/app/migrate_keymap.go @@ -0,0 +1,47 @@ +package app + +import "github.com/charmbracelet/bubbles/key" + +type migrateKeymap struct { + Exit key.Binding + Up key.Binding + Down key.Binding + Goto key.Binding + Config key.Binding + New key.Binding +} + +var defaultMigrateKeymap = migrateKeymap{ + Exit: key.NewBinding( + key.WithKeys("ctrl+c"), + key.WithHelp("ctrl+c", "exit"), + ), + Up: key.NewBinding( + key.WithKeys("u"), + key.WithHelp("u", "up"), + ), + Down: key.NewBinding( + key.WithKeys("d"), + key.WithHelp("d", "down"), + ), + Goto: key.NewBinding( + key.WithKeys("g"), + key.WithHelp("g", "goto"), + ), + Config: key.NewBinding( + key.WithKeys("c"), + key.WithHelp("c", "config"), + ), + New: key.NewBinding( + key.WithKeys("n"), + key.WithHelp("n", "new"), + ), +} + +func (m migrateKeymap) ShortHelp() []key.Binding { + return []key.Binding{m.Exit, m.Up, m.Down, m.Goto, m.Config, m.New} +} + +func (m migrateKeymap) FullHelp() [][]key.Binding { + return [][]key.Binding{m.ShortHelp()} +} diff --git a/app/migrate_model.go b/app/migrate_model.go new file mode 100644 index 0000000..8392333 --- /dev/null +++ b/app/migrate_model.go @@ -0,0 +1,180 @@ +package app + +import ( + "fmt" + _ "github.com/Vaniog/lazymigrate/app/build" + "github.com/charmbracelet/bubbles/help" + "github.com/charmbracelet/bubbles/key" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/lipgloss/table" + "github.com/golang-migrate/migrate/v4" + _ "github.com/golang-migrate/migrate/v4/source/file" + "os" +) + +type migrateModel struct { + sourceFile string + databaseUrl string + + migrate *migrate.Migrate + err error + + help help.Model + keymap migrateKeymap + + logModel logModel +} + +type setMigrateMsg struct { + migrate *migrate.Migrate +} +type setMigrateErrMsg struct { + err error +} +type gotoMigrationMsg struct { + version uint +} + +func newMigrateModel(sourceUrl, databaseUrl string) migrateModel { + mm := migrateModel{ + sourceFile: sourceUrl, + databaseUrl: databaseUrl, + logModel: defaultLogModel, + keymap: defaultMigrateKeymap, + } + + mm.help = help.New() + return mm +} + +func (mm migrateModel) Init() tea.Cmd { + migrateCmd := func() tea.Msg { + m, err := migrate.New( + fmt.Sprintf("file://%s", mm.sourceFile), + mm.databaseUrl, + ) + if err != nil { + return setMigrateErrMsg{err} + } + + m.Log = mm.logModel.lineLogger + return setMigrateMsg{m} + } + + return tea.Batch(migrateCmd, mm.logModel.Init()) +} + +func (mm migrateModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + switch { + case key.Matches(msg, mm.keymap.Exit): + return mm, tea.Quit + case key.Matches(msg, mm.keymap.Config): + cm := newConfigModel(mm) + return cm, cm.Init() + case key.Matches(msg, mm.keymap.Up): + if mm.migrate == nil { + mm.logModel.lineLogger.Printf("no connection") + return mm, nil + } + err := mm.migrate.Up() + if err != nil { + mm.logModel.lineLogger.Printf("up error: %s", err) + } else { + mm.logModel.lineLogger.Printf("up succeed") + } + return mm, nil + case key.Matches(msg, mm.keymap.Down): + if mm.migrate == nil { + mm.logModel.lineLogger.Printf("no connection") + return mm, nil + } + err := mm.migrate.Down() + if err != nil { + mm.logModel.lineLogger.Printf("down error: %s", err) + } else { + mm.logModel.lineLogger.Printf("down succeed") + } + return mm, nil + case key.Matches(msg, mm.keymap.Goto): + if mm.migrate == nil { + mm.logModel.lineLogger.Printf("no connection") + return mm, nil + } + gm := newGotoModel(mm) + return gm, gm.Init() + case key.Matches(msg, mm.keymap.New): + cmm := newCreateMigrationModel(mm) + return cmm, cmm.Init() + } + case setMigrateMsg: + mm.migrate = msg.migrate + return mm, nil + case setMigrateErrMsg: + mm.err = msg.err + return mm, nil + case logModelTickMessage: + _, cmd := mm.logModel.Update(msg) + return mm, cmd + case gotoMigrationMsg: + err := mm.migrate.Migrate(msg.version) + if err != nil { + mm.logModel.lineLogger.Printf("goto error: %s", err) + } else { + mm.logModel.lineLogger.Printf("goto succeed") + } + } + + return mm, nil +} + +func (mm migrateModel) View() string { + configTable := table.New() + configTable.Row("Database", mm.databaseUrl) + configTable.Row("Source", mm.sourceFile) + configTable.Border(lipgloss.NormalBorder()) + + statusTable := table.New() + + if mm.err != nil { + statusTable.Row("Status", "Error") + statusTable.Row("Error", mm.err.Error()) + } else if mm.migrate != nil { + version, dirty, _ := mm.migrate.Version() + statusTable.Row("Status", "Connected") + statusTable.Row("Version", fmt.Sprintf("%d", version)) + statusTable.Row("Dirty", fmt.Sprintf("%t", dirty)) + } else { + statusTable.Row("Status", "Connecting ...") + } + + re := lipgloss.NewRenderer(os.Stdout) + styleTable := func(t *table.Table) { + leftStyle := re.NewStyle().Padding(0, 1).Width(12) + rightStyle := re.NewStyle().Padding(0, 1).Foreground(lipgloss.Color("7")) + t.Border(lipgloss.NormalBorder()) + t.BorderStyle(re.NewStyle().Foreground(lipgloss.Color("238"))) + t.StyleFunc(func(_, col int) lipgloss.Style { + if col == 0 { + return leftStyle + } + return rightStyle + }) + } + + styleTable(configTable) + styleTable(statusTable) + + logsStyle := lipgloss.NewStyle().Height(6) + + view := lipgloss.JoinVertical( + 0, + configTable.Render(), + statusTable.Render(), + logsStyle.Render(mm.logModel.View()), + mm.help.View(mm.keymap), + ) + return view +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d1f2448 --- /dev/null +++ b/go.mod @@ -0,0 +1,61 @@ +module github.com/Vaniog/lazymigrate + +go 1.22.0 + +require ( + github.com/charmbracelet/bubbles v0.18.0 + github.com/charmbracelet/bubbletea v0.26.3 + github.com/charmbracelet/lipgloss v0.9.1 + github.com/golang-migrate/migrate/v4 v4.17.1 + github.com/jackc/pgx/v5 v5.5.4 + github.com/joho/godotenv v1.5.1 + github.com/kelseyhightower/envconfig v1.4.0 +) + +require ( + github.com/atotto/clipboard v0.1.4 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/x/ansi v0.1.1 // indirect + github.com/charmbracelet/x/input v0.1.0 // indirect + github.com/charmbracelet/x/term v0.1.1 // indirect + github.com/charmbracelet/x/windows v0.1.0 // indirect + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect + github.com/go-sql-driver/mysql v1.5.0 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/lib/pq v1.10.9 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect + github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/reflow v0.3.0 // indirect + github.com/muesli/termenv v0.15.2 // indirect + github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + go.uber.org/atomic v1.7.0 // indirect + golang.org/x/crypto v0.20.0 // indirect + golang.org/x/mod v0.11.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.10.0 // indirect + lukechampine.com/uint128 v1.2.0 // indirect + modernc.org/cc/v3 v3.36.3 // indirect + modernc.org/ccgo/v3 v3.16.9 // indirect + modernc.org/libc v1.17.1 // indirect + modernc.org/mathutil v1.5.0 // indirect + modernc.org/memory v1.2.1 // indirect + modernc.org/opt v0.1.3 // indirect + modernc.org/sqlite v1.18.1 // indirect + modernc.org/strutil v1.1.3 // indirect + modernc.org/token v1.0.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fd3a548 --- /dev/null +++ b/go.sum @@ -0,0 +1,205 @@ +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0= +github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw= +github.com/charmbracelet/bubbletea v0.26.3 h1:iXyGvI+FfOWqkB2V07m1DF3xxQijxjY2j8PqiXYqasg= +github.com/charmbracelet/bubbletea v0.26.3/go.mod h1:bpZHfDHTYJC5g+FBK+ptJRCQotRC+Dhh3AoMxa/2+3Q= +github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg= +github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I= +github.com/charmbracelet/x/ansi v0.1.1 h1:CGAduulr6egay/YVbGc8Hsu8deMg1xZ/bkaXTPi1JDk= +github.com/charmbracelet/x/ansi v0.1.1/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/input v0.1.0 h1:TEsGSfZYQyOtp+STIjyBq6tpRaorH0qpwZUj8DavAhQ= +github.com/charmbracelet/x/input v0.1.0/go.mod h1:ZZwaBxPF7IG8gWWzPUVqHEtWhc1+HXJPNuerJGRGZ28= +github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI= +github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= +github.com/charmbracelet/x/windows v0.1.0 h1:gTaxdvzDM5oMa/I2ZNF7wN78X/atWemG9Wph7Ika2k4= +github.com/charmbracelet/x/windows v0.1.0/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dhui/dktest v0.4.1 h1:/w+IWuDXVymg3IrRJCHHOkMK10m9aNVMOyD0X12YVTg= +github.com/dhui/dktest v0.4.1/go.mod h1:DdOqcUpL7vgyP4GlF3X3w7HbSlz8cEQzwewPveYEQbA= +github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= +github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0= +github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= +github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4= +github.com/golang-migrate/migrate/v4 v4.17.1/go.mod h1:m8hinFyWBn0SA4QKHuKh175Pm9wjmxj3S2Mia7dbXzM= +github.com/google/go-cmp v0.5.3 h1:x95R7cp+rSeeqAMI2knLtQ0DKlaBhv2NrtrOvafPHRo= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.5.4 h1:Xp2aQS8uXButQdnCMWNmvx6UysWQQC+u1EoizjguY+8= +github.com/jackc/pgx/v5 v5.5.4/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= +github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= +github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= +github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= +github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= +github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= +github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= +github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= +github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= +github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= +github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= +github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= +github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk= +github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y= +github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg= +golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ= +golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo= +golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg= +golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= +lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI= +lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= +modernc.org/cc/v3 v3.36.2/go.mod h1:NFUHyPn4ekoC/JHeZFfZurN6ixxawE1BnVonP/oahEI= +modernc.org/cc/v3 v3.36.3 h1:uISP3F66UlixxWEcKuIWERa4TwrZENHSL8tWxZz8bHg= +modernc.org/cc/v3 v3.36.3/go.mod h1:NFUHyPn4ekoC/JHeZFfZurN6ixxawE1BnVonP/oahEI= +modernc.org/ccgo/v3 v3.16.9 h1:AXquSwg7GuMk11pIdw7fmO1Y/ybgazVkMhsZWCV0mHM= +modernc.org/ccgo/v3 v3.16.9/go.mod h1:zNMzC9A9xeNUepy6KuZBbugn3c0Mc9TeiJO4lgvkJDo= +modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk= +modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ= +modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM= +modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM= +modernc.org/libc v1.17.0/go.mod h1:XsgLldpP4aWlPlsjqKRdHPqCxCjISdHfM/yeWC5GyW0= +modernc.org/libc v1.17.1 h1:Q8/Cpi36V/QBfuQaFVeisEBs3WqoGAJprZzmf7TfEYI= +modernc.org/libc v1.17.1/go.mod h1:FZ23b+8LjxZs7XtFMbSzL/EhPxNbfZbErxEHc7cbD9s= +modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= +modernc.org/mathutil v1.4.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= +modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= +modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= +modernc.org/memory v1.2.0/go.mod h1:/0wo5ibyrQiaoUoH7f9D8dnglAmILJ5/cxZlRECf+Nw= +modernc.org/memory v1.2.1 h1:dkRh86wgmq/bJu2cAS2oqBCz/KsMZU7TUM4CibQ7eBs= +modernc.org/memory v1.2.1/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= +modernc.org/opt v0.1.1/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= +modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= +modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= +modernc.org/sqlite v1.18.1 h1:ko32eKt3jf7eqIkCgPAeHMBXw3riNSLhl2f3loEF7o8= +modernc.org/sqlite v1.18.1/go.mod h1:6ho+Gow7oX5V+OiOQ6Tr4xeqbx13UZ6t+Fw9IRUG4d4= +modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw= +modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY= +modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw= +modernc.org/tcl v1.13.1 h1:npxzTwFTZYM8ghWicVIX1cRWzj7Nd8i6AqqX2p+IYao= +modernc.org/tcl v1.13.1/go.mod h1:XOLfOwzhkljL4itZkK6T72ckMgvj0BDsnKNdZVUOecw= +modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk= +modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= +modernc.org/z v1.5.1 h1:RTNHdsrOpeoSeOF4FbzTo8gBYByaJ5xT7NgZ9ZqRiJM= +modernc.org/z v1.5.1/go.mod h1:eWFB510QWW5Th9YGZT81s+LwvaAs3Q2yr4sP0rmLkv8= diff --git a/main.go b/main.go new file mode 100644 index 0000000..e74f315 --- /dev/null +++ b/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "github.com/Vaniog/lazymigrate/app" + "log" +) + +func main() { + a := app.NewApp() + if err := a.Run(); err != nil { + log.Fatal(err) + } +}