diff --git a/migrations/list_tables/main.go b/migrations/list_tables/main.go new file mode 100644 index 00000000..21db4d5c --- /dev/null +++ b/migrations/list_tables/main.go @@ -0,0 +1,34 @@ +package list + +import ( + "fmt" + "slices" + + "migrate/kdvh" +) + +type Config struct { + System string `short:"d" long:"db" default:"all" choice:"kdvh" choice:"kvlaobs" choice:"all" description:"Name of the database you want to dump data from"` +} + +func (config *Config) Execute(_ []string) error { + if config.System == "kdvh" || config.System == "all" { + fmt.Println("Available tables in KDVH:") + + var tables []string + for table := range kdvh.Init().Tables { + tables = append(tables, table) + } + + slices.Sort(tables) + for _, table := range tables { + fmt.Println(" -", table) + } + } + + if config.System == "kvalobs" || config.System == "all" { + // TODO + } + + return nil +} diff --git a/migrations/main.go b/migrations/main.go index 89a24466..e9a1fd0c 100644 --- a/migrations/main.go +++ b/migrations/main.go @@ -9,22 +9,15 @@ import ( "migrate/dump" "migrate/import" + "migrate/list_tables" ) type CmdArgs struct { - List ListConfig `command:"list" description:"List available tables"` + List list.Config `command:"list" description:"List available tables"` Dump dump.Config `command:"dump" description:"Dump tables from KDVH to CSV"` Import port.Config `command:"import" description:"Import dumped CSV files"` } -type ListConfig struct{} - -func (config *ListConfig) Execute(_ []string) error { - fmt.Println("Available tables:") - // TODO: refactor - return nil -} - func main() { log.SetFlags(log.LstdFlags | log.Lshortfile)