Skip to content

Commit 9945485

Browse files
authored
db tools preliminary work; --src.schema changes (#392)
- Preliminary work on the (currently hidden) `db` cmds. - Improvements to `--src.schema`
1 parent 4a884e1 commit 9945485

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2603
-265
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ _testmain.go
4242
.envrc
4343
**/*.bench
4444
go.work*
45-
45+
*.dump.sql
4646
# Some apps create temp files when editing, e.g. Excel with drivers/xlsx/testdata/~$test_header.xlsx
4747
**/testdata/~*
4848

@@ -59,3 +59,5 @@ goreleaser-test.sh
5959
/*.db
6060
/.CHANGELOG.delta.md
6161
/testh/progress-remove.test.sh
62+
63+
/*.dump

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
Breaking changes are annotated with ☢️, and alpha/beta features with 🐥.
99

1010

11+
## [v0.47.4] - UPCOMING
12+
13+
Minor changes to the behavior of the `--src.schema` flag.
14+
See the earlier [`v0.47.0`](https://github.com/neilotoole/sq/releases/tag/v0.47.0)
15+
release for recent headline features.
16+
17+
### Changed
18+
19+
- The [`--src.schema`](https://sq.io/docs/source#source-override) flag (as used in [`sq inspect`](https://sq.io/docs/cmd/inspect),
20+
[`sq sql`](https://sq.io/docs/cmd/sql), and the root [`sq`](https://sq.io/docs/cmd/sq#override-active-schema) cmd)
21+
now accepts `--src.schema=CATALOG.` (note the `.` suffix). This is in addition to the existing allowed forms `SCHEMA`
22+
and `CATALOG.SCHEMA`. This new `CATALOG.` form is effectively equivalent to `CATALOG.CURRENT_SCHEMA`.
23+
24+
```shell
25+
# Inspect using the default schema in the "sales" catalog
26+
$ sq inspect --src.schema=sales.
27+
```
28+
29+
- The [`--src.schema`](https://sq.io/docs/source#source-override) flag is now validated. Previously, if you provided a non-existing catalog or schema
30+
value, `sq` would silently ignore it and use the defaults. This could mislead the user into thinking that
31+
they were getting valid results from the non-existent catalog or schema. Now an error is returned.
32+
33+
1134
## [v0.47.3] - 2024-02-03
1235

1336
Minor bug fix release. See the earlier [`v0.47.0`](https://github.com/neilotoole/sq/releases/tag/v0.47.0)
@@ -1138,3 +1161,4 @@ make working with lots of sources much easier.
11381161
[v0.47.1]: https://github.com/neilotoole/sq/compare/v0.47.0...v0.47.1
11391162
[v0.47.2]: https://github.com/neilotoole/sq/compare/v0.47.1...v0.47.2
11401163
[v0.47.3]: https://github.com/neilotoole/sq/compare/v0.47.2...v0.47.3
1164+
[v0.47.4]: https://github.com/neilotoole/sq/compare/v0.47.3...v0.47.4

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ gen:
2929
.PHONY: fmt
3030
fmt:
3131
@# https://github.com/incu6us/goimports-reviser
32-
@# Note that *_windows.go is excluded because the tool seems
32+
@# Note that termz_windows.go is excluded because the tool seems
3333
@# to mangle Go code that is guarded by build tags that
34-
@# are not in use.
34+
@# are not in use. Alas, we can't provide a double star glob,
35+
@# e.g. **/*_windows.go, because filepath.Match doesn't support
36+
@# double star, so we explicitly name the file.
3537
@goimports-reviser -company-prefixes github.com/neilotoole -set-alias \
36-
-excludes '**/*_windows.go' \
38+
-excludes 'libsq/core/termz/termz_windows.go' \
3739
-rm-unused -output write \
3840
-project-name github.com/neilotoole/sq ./...
3941

cli/cli.go

+9
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ func newCommandTree(ru *run.Run) (rootCmd *cobra.Command) {
259259
addCmd(ru, tblCmd, newTblTruncateCmd())
260260
addCmd(ru, tblCmd, newTblDropCmd())
261261

262+
dbCmd := addCmd(ru, rootCmd, newDBCmd())
263+
addCmd(ru, dbCmd, newDBExecCmd())
264+
dbDumpCmd := addCmd(ru, dbCmd, newDBDumpCmd())
265+
addCmd(ru, dbDumpCmd, newDBDumpCatalogCmd())
266+
addCmd(ru, dbDumpCmd, newDBDumpClusterCmd())
267+
dbRestoreCmd := addCmd(ru, dbCmd, newDBRestoreCmd())
268+
addCmd(ru, dbRestoreCmd, newDBRestoreCatalogCmd())
269+
addCmd(ru, dbRestoreCmd, newDBRestoreClusterCmd())
270+
262271
addCmd(ru, rootCmd, newDiffCmd())
263272

264273
driverCmd := addCmd(ru, rootCmd, newDriverCmd())

cli/cmd_add.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ More examples:
156156
Long: `Add data source specified by LOCATION, optionally identified by @HANDLE.`,
157157
}
158158

159-
markCmdRequiresConfigLock(cmd)
159+
cmdMarkRequiresConfigLock(cmd)
160160
addTextFormatFlags(cmd)
161161
cmd.Flags().BoolP(flag.JSON, flag.JSONShort, false, flag.JSONUsage)
162162
cmd.Flags().BoolP(flag.Compact, flag.CompactShort, false, flag.CompactUsage)
@@ -242,7 +242,7 @@ func execSrcAdd(cmd *cobra.Command, args []string) error {
242242
// or sq prompts the user.
243243
if cmdFlagIsSetTrue(cmd, flag.PasswordPrompt) {
244244
var passwd []byte
245-
if passwd, err = readPassword(ctx, ru.Stdin, ru.Out, ru.Writers.Printing); err != nil {
245+
if passwd, err = readPassword(ctx, ru.Stdin, ru.Out, ru.Writers.OutPrinting); err != nil {
246246
return err
247247
}
248248

cli/cmd_add_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,12 @@ func TestCmdAdd(t *testing.T) {
141141
wantHandle: "@sakila",
142142
wantType: drivertype.SQLite,
143143
},
144-
145144
{
146145
// with scheme
147146
loc: proj.Abs(sakila.PathSL3),
148147
wantHandle: "@sakila",
149148
wantType: drivertype.SQLite,
150149
},
151-
152150
{
153151
// without scheme, relative path
154152
loc: proj.Rel(sakila.PathSL3),

cli/cmd_cache.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func newCacheStatCmd() *cobra.Command {
7474
/Users/neilotoole/Library/Caches/sq/f36ac695 enabled (472.8MB)`,
7575
}
7676

77-
markCmdRequiresConfigLock(cmd)
77+
cmdMarkRequiresConfigLock(cmd)
7878
addTextFormatFlags(cmd)
7979
cmd.Flags().BoolP(flag.JSON, flag.JSONShort, false, flag.JSONUsage)
8080
cmd.Flags().BoolP(flag.YAML, flag.YAMLShort, false, flag.YAMLUsage)
@@ -111,7 +111,7 @@ func newCacheClearCmd() *cobra.Command {
111111
$ sq cache clear @sakila`,
112112
}
113113

114-
markCmdRequiresConfigLock(cmd)
114+
cmdMarkRequiresConfigLock(cmd)
115115
return cmd
116116
}
117117

@@ -150,7 +150,7 @@ func newCacheTreeCmd() *cobra.Command {
150150
$ sq cache tree --size`,
151151
}
152152

153-
markCmdRequiresConfigLock(cmd)
153+
cmdMarkRequiresConfigLock(cmd)
154154
_ = cmd.Flags().BoolP(flag.CacheTreeSize, flag.CacheTreeSizeShort, false, flag.CacheTreeSizeUsage)
155155
return cmd
156156
}
@@ -163,7 +163,7 @@ func execCacheTree(cmd *cobra.Command, _ []string) error {
163163
}
164164

165165
showSize := cmdFlagBool(cmd, flag.CacheTreeSize)
166-
return ioz.PrintTree(ru.Out, cacheDir, showSize, !ru.Writers.Printing.IsMonochrome())
166+
return ioz.PrintTree(ru.Out, cacheDir, showSize, !ru.Writers.OutPrinting.IsMonochrome())
167167
}
168168

169169
func newCacheEnableCmd() *cobra.Command { //nolint:dupl
@@ -200,7 +200,7 @@ func newCacheEnableCmd() *cobra.Command { //nolint:dupl
200200
$ sq cache enable @sakila`,
201201
}
202202

203-
markCmdRequiresConfigLock(cmd)
203+
cmdMarkRequiresConfigLock(cmd)
204204
return cmd
205205
}
206206

@@ -238,6 +238,6 @@ func newCacheDisableCmd() *cobra.Command { //nolint:dupl
238238
$ sq cache disable @sakila`,
239239
}
240240

241-
markCmdRequiresConfigLock(cmd)
241+
cmdMarkRequiresConfigLock(cmd)
242242
return cmd
243243
}

cli/cmd_config_edit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ in envar $SQ_EDITOR or $EDITOR.`,
5151
# Use a different editor
5252
$ SQ_EDITOR=nano sq config edit`,
5353
}
54-
markCmdRequiresConfigLock(cmd)
54+
cmdMarkRequiresConfigLock(cmd)
5555
return cmd
5656
}
5757

@@ -134,7 +134,7 @@ func execConfigEditSource(cmd *cobra.Command, args []string) error {
134134

135135
// The Catalog and Schema fields have yaml tag 'omitempty',
136136
// so they wouldn't be rendered in the editor yaml if empty.
137-
// However, we to render the fields commented-out if empty.
137+
// However, we want to render the fields commented-out if empty.
138138
// Hence this little hack.
139139
if tmpSrc.Catalog == "" {
140140
// Forces yaml rendering

cli/cmd_config_set.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Use "sq config ls -v" to list available options.`,
4141
# Help for an individual option
4242
$ sq config set conn.max-open --help`,
4343
}
44-
markCmdRequiresConfigLock(cmd)
44+
cmdMarkRequiresConfigLock(cmd)
4545
addTextFormatFlags(cmd)
4646
cmd.Flags().BoolP(flag.JSON, flag.JSONShort, false, flag.JSONUsage)
4747
cmd.Flags().BoolP(flag.Compact, flag.CompactShort, false, flag.CompactUsage)

cli/cmd_db.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cli
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
func newDBCmd() *cobra.Command {
8+
cmd := &cobra.Command{
9+
Use: "db",
10+
Short: "Useful database actions",
11+
RunE: func(cmd *cobra.Command, args []string) error {
12+
return cmd.Help()
13+
},
14+
Example: ` # TBD`,
15+
}
16+
17+
return cmd
18+
}

0 commit comments

Comments
 (0)