diff --git a/migrations/go.mod b/migrations/go.mod index d7233f7b..5deeb931 100644 --- a/migrations/go.mod +++ b/migrations/go.mod @@ -25,3 +25,5 @@ require ( golang.org/x/term v0.25.0 // indirect golang.org/x/text v0.16.0 // indirect ) + +replace github.com/jessevdk/go-flags => github.com/Lun4m/go-flags v0.0.0-20241113125827-68757125e949 diff --git a/migrations/go.sum b/migrations/go.sum index 22ed9b76..2d0a2d0b 100644 --- a/migrations/go.sum +++ b/migrations/go.sum @@ -1,3 +1,5 @@ +github.com/Lun4m/go-flags v0.0.0-20241113125827-68757125e949 h1:7xyEGIr1X5alOjBjlNTDF+aRBcRIo60YX5sdlziLE5w= +github.com/Lun4m/go-flags v0.0.0-20241113125827-68757125e949/go.mod h1:42/L0FDbP0qe91I+81tBqjU3uoz1tn1GDMZAhcCE2PE= github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM= github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -35,8 +37,6 @@ github.com/rickb777/plural v1.4.2 h1:Kl/syFGLFZ5EbuV8c9SVud8s5HI2HpCCtOMw2U1kS+A github.com/rickb777/plural v1.4.2/go.mod h1:kdmXUpmKBJTS0FtG/TFumd//VBWsNTD7zOw7x4umxNw= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM= -github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs= github.com/schollz/progressbar/v3 v3.16.1 h1:RnF1neWZFzLCoGx8yp1yF7SDl4AzNDI5y4I0aUJRrZQ= github.com/schollz/progressbar/v3 v3.16.1/go.mod h1:I2ILR76gz5VXqYMIY/LdLecvMHDPVcQm3W/MSKi1TME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/migrations/kdvh/dump.go b/migrations/kdvh/dump.go index e36391e0..db069c71 100644 --- a/migrations/kdvh/dump.go +++ b/migrations/kdvh/dump.go @@ -15,33 +15,15 @@ import ( ) type DumpConfig struct { - BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"` - TablesCmd string `short:"t" long:"table" default:"" description:"Optional comma separated list of table names. By default all available tables are processed"` - StationsCmd string `short:"s" long:"stnr" default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"` - ElementsCmd string `short:"e" long:"elem" default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"` - Overwrite bool `long:"overwrite" description:"Overwrite any existing dumped files"` - Email []string `long:"email" description:"Optional email address used to notify if the program crashed"` - - Tables []string - Stations []string - Elements []string -} - -func (config *DumpConfig) setup() { - if config.TablesCmd != "" { - config.Tables = strings.Split(config.TablesCmd, ",") - } - if config.StationsCmd != "" { - config.Stations = strings.Split(config.StationsCmd, ",") - } - if config.ElementsCmd != "" { - config.Elements = strings.Split(config.ElementsCmd, ",") - } + BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"` + Tables []string `short:"t" delimiter:"," long:"table" default:"" description:"Optional comma separated list of table names. By default all available tables are processed"` + Stations []string `short:"s" delimiter:"," long:"stnr" default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"` + Elements []string `short:"e" delimiter:"," long:"elem" default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"` + Overwrite bool `long:"overwrite" description:"Overwrite any existing dumped files"` + Email []string `long:"email" delimiter:"," description:"Optional comma separated list of email addresses used to notify if the program crashed"` } func (config *DumpConfig) Execute([]string) error { - config.setup() - conn, err := sql.Open("pgx", os.Getenv("KDVH_PROXY_CONN")) if err != nil { slog.Error(err.Error()) diff --git a/migrations/kdvh/import.go b/migrations/kdvh/import.go index b593fac6..b323d651 100644 --- a/migrations/kdvh/import.go +++ b/migrations/kdvh/import.go @@ -22,19 +22,15 @@ import ( ) type ImportConfig struct { - Verbose bool `short:"v" description:"Increase verbosity level"` - BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"` - TablesCmd string `short:"t" long:"table" default:"" description:"Optional comma separated list of table names. By default all available tables are processed"` - StationsCmd string `short:"s" long:"station" default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"` - ElementsCmd string `short:"e" long:"elemcode" default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"` - Sep string `long:"sep" default:"," description:"Separator character in the dumped files. Needs to be quoted"` - HasHeader bool `long:"header" description:"Add this flag if the dumped files have a header row"` - Skip string `long:"skip" choice:"data" choice:"flags" description:"Skip import of data or flags"` - Email []string `long:"email" description:"Optional email address used to notify if the program crashed"` - - Tables []string - Stations []string - Elements []string + Verbose bool `short:"v" description:"Increase verbosity level"` + BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"` + Tables []string `short:"t" long:"table" delimiter:"," default:"" description:"Optional comma separated list of table names. By default all available tables are processed"` + Stations []string `short:"s" long:"station" delimiter:"," default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"` + Elements []string `short:"e" long:"elemcode" delimiter:"," default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"` + Sep string `long:"sep" default:"," description:"Separator character in the dumped files. Needs to be quoted"` + HasHeader bool `long:"header" description:"Add this flag if the dumped files have a header row"` + Skip string `long:"skip" choice:"data" choice:"flags" description:"Skip import of data or flags"` + Email []string `long:"email" delimiter:"," description:"Optional comma separated list of email addresses used to notify if the program crashed"` OffsetMap map[StinfoKey]period.Period // Map of offsets used to correct (?) KDVH times for specific parameters StinfoMap map[StinfoKey]StinfoParam // Map of metadata used to query timeseries ID in LARD @@ -46,15 +42,6 @@ func (config *ImportConfig) setup() { fmt.Printf("Error: '--sep' only accepts single-byte characters. Got %s", config.Sep) os.Exit(1) } - if config.TablesCmd != "" { - config.Tables = strings.Split(config.TablesCmd, ",") - } - if config.StationsCmd != "" { - config.Stations = strings.Split(config.StationsCmd, ",") - } - if config.ElementsCmd != "" { - config.Elements = strings.Split(config.ElementsCmd, ",") - } config.CacheMetadata() }