Skip to content

Commit 9b1145c

Browse files
fix(apps): make db --environment optional, auto-select branch server-side
All db shortcuts defaulted --environment to "dev", which forced single-env apps (whose DB lives on the online branch, with no dev branch) to fail with "Invalid DB Branch: dev" unless the user explicitly passed --environment online. Change the default to empty: when --environment is omitted the CLI sends no env, letting the server pick the branch by the app's multi-env state (multi-env → dev, single-env → online), matching miaoda-cli's behavior of not carrying dbBranch when unset. Explicit --environment dev|online is unchanged; explicit dev on a single-env app still errors as expected. - 10 db shortcuts: dbEnvFlags default "dev" → "" (+db-execute, +db-table-list, +db-table-get, +db-quota-get, +db-data-export, +db-data-import, +db-changelog-list, +db-audit-list/-set/-status) - dry-run e2e assertions updated: default env is now unset, not "dev" - skill docs (lark-apps-db, lark-apps-db-execute) describe the auto-select Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 73be1d0 commit 9b1145c

14 files changed

Lines changed: 20 additions & 19 deletions

shortcuts/apps/apps_db_audit_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var AppsDBAuditList = common.Shortcut{
4040
{Name: "until", Desc: "filter: event at or before; same formats as --since"},
4141
{Name: "page-size", Type: "int", Default: "20", Desc: "page size"},
4242
{Name: "page-token", Desc: "pagination cursor from previous response"},
43-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
43+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
4444
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
4545
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
4646
return err

shortcuts/apps/apps_db_audit_set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var AppsDBAuditEnable = common.Shortcut{
3535
{Name: "app-id", Desc: "Miaoda app id", Required: true},
3636
{Name: "table", Desc: "table to enable audit for", Required: true},
3737
{Name: "retention", Default: "7d", Enum: auditRetentions, Desc: "how long to keep audit logs"},
38-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
38+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
3939
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
4040
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
4141
return err
@@ -96,7 +96,7 @@ var AppsDBAuditDisable = common.Shortcut{
9696
Flags: append([]common.Flag{
9797
{Name: "app-id", Desc: "Miaoda app id", Required: true},
9898
{Name: "table", Desc: "table to disable audit for", Required: true},
99-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
99+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
100100
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
101101
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
102102
return err

shortcuts/apps/apps_db_audit_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var AppsDBAuditStatus = common.Shortcut{
3030
Flags: append([]common.Flag{
3131
{Name: "app-id", Desc: "Miaoda app id", Required: true},
3232
{Name: "table", Desc: "show status for a single table (default: all configured tables)"},
33-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
33+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
3434
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
3535
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
3636
return err

shortcuts/apps/apps_db_changelog_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var AppsDBChangelogList = common.Shortcut{
3939
{Name: "until", Desc: "filter: changed at or before; same formats as --since"},
4040
{Name: "page-size", Type: "int", Default: "20", Desc: "page size"},
4141
{Name: "page-token", Desc: "pagination cursor from previous response"},
42-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
42+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
4343
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
4444
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
4545
return err

shortcuts/apps/apps_db_data_export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var AppsDBDataExport = common.Shortcut{
4747
{Name: "table", Desc: "source table", Required: true},
4848
{Name: "output", Desc: "local output path; extension picks format .csv/.json/.sql (default: <table>.csv)"},
4949
{Name: "limit", Type: "int", Default: "5000", Desc: "max rows to export (1..5000)"},
50-
}, dbEnvFlags("dev", []string{"dev", "online"}, "source db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
50+
}, dbEnvFlags("", []string{"dev", "online"}, "source db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
5151
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
5252
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
5353
return err

shortcuts/apps/apps_db_data_import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var AppsDBDataImport = common.Shortcut{
4444
{Name: "app-id", Desc: "Miaoda app id", Required: true},
4545
{Name: "file", Desc: "local data file (.csv/.json), relative to cwd", Required: true},
4646
{Name: "table", Desc: "target table (default: file name without extension)"},
47-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
47+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
4848
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
4949
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
5050
return err

shortcuts/apps/apps_db_execute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var AppsDBExecute = common.Shortcut{
6666
{Name: "sql", Desc: "SQL text; use - to read stdin. Mutually exclusive with --file",
6767
Input: []string{common.Stdin}},
6868
{Name: "file", Desc: "path to a .sql file (relative to cwd). Mutually exclusive with --sql"},
69-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
69+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
7070
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
7171
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
7272
return err

shortcuts/apps/apps_db_quota_get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var AppsDBQuotaGet = common.Shortcut{
2929
HasFormat: true,
3030
Flags: append([]common.Flag{
3131
{Name: "app-id", Desc: "Miaoda app id", Required: true},
32-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
32+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
3333
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
3434
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
3535
return err

shortcuts/apps/apps_db_table_get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var AppsDBTableGet = common.Shortcut{
3737
Flags: append([]common.Flag{
3838
{Name: "app-id", Desc: "app id", Required: true},
3939
{Name: "table", Desc: "table name", Required: true},
40-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
40+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
4141
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
4242
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
4343
return err

shortcuts/apps/apps_db_table_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var AppsDBTableList = common.Shortcut{
4242
{Name: "app-id", Desc: "app id", Required: true},
4343
{Name: "page-size", Type: "int", Default: "20", Desc: "page size"},
4444
{Name: "page-token", Desc: "pagination cursor from previous response"},
45-
}, dbEnvFlags("dev", []string{"dev", "online"}, "target db environment (default dev; use online for the online environment, or for an app whose DB is not multi-env)")...),
45+
}, dbEnvFlags("", []string{"dev", "online"}, "target db environment; leave unset to auto-select (multi-env app uses dev, single-env uses online), or pass dev/online")...),
4646
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
4747
if _, err := requireAppID(rctx.Str("app-id")); err != nil {
4848
return err

0 commit comments

Comments
 (0)