diff --git a/.changeset/cli-targets.md b/.changeset/cli-targets.md new file mode 100644 index 00000000..a2224ee8 --- /dev/null +++ b/.changeset/cli-targets.md @@ -0,0 +1,11 @@ +--- +'@powersync/cli-schemas': minor +'@powersync/cli-core': minor +'powersync': minor +--- + +Added named targets to `cli.yaml`. Link several Cloud instances from one project directory with `powersync link cloud --target= --instance-id=`, then pick one per command with `--target=` or the `POWERSYNC_TARGET` variable. The top-level `instance_id`, `org_id` and `project_id` fields remain the default target. + +- `powersync fetch instances` lists the targets of each linked directory. +- Commands that work with both Cloud and self-hosted instances now let `--instance-id` or `--api-url` decide the context, even when `cli.yaml` is linked to the other type. +- When a linked directory has no `service.yaml`, the error now suggests `powersync pull instance`. diff --git a/.gitignore b/.gitignore index 502a4c85..2ea100fc 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,4 @@ playground/ # IDE .idea + diff --git a/cli/README.md b/cli/README.md index 17de9234..2bc32285 100644 --- a/cli/README.md +++ b/cli/README.md @@ -154,7 +154,19 @@ export INSTANCE_ID= powersync generate schema --output-path=schema.ts --output=ts ``` -**Tip:** To avoid passing `--instance-id` on every command, run **`powersync link cloud --instance-id=`** once. The CLI writes `cli.yaml` in the current directory, and subsequent commands use that instance without flags or env vars. +**Tip:** To avoid passing `--instance-id` on every command, run **`powersync link cloud --instance-id=`** once. The CLI writes `cli.yaml` in the current directory, and subsequent commands use that instance without flags or env vars. To work with several instances from one directory, see the next section. + +## Several instances from one directory + +Link each instance as a named target, then pick one per command: + +```sh +powersync link cloud --target=staging --instance-id= +powersync deploy --target=staging +POWERSYNC_TARGET=staging powersync deploy sync-config # for scripts and CI +``` + +Commands without a target use the top-level link in `cli.yaml`. See [docs/usage.md](../docs/usage.md#configuring-multiple-instances-eg-dev-staging-production) for the full walkthrough. # Self-hosted @@ -253,6 +265,7 @@ You can supply instance and auth context via environment variables (useful for C - **`PS_ADMIN_TOKEN`** — PowerSync personal access token for Cloud commands. [Learn more](https://docs.powersync.com/usage/tools/cli#personal-access-token). - **`INSTANCE_ID`** — Instance ID (Cloud). Get IDs from the [PowerSync Dashboard](https://dashboard.powersync.com) or **`powersync fetch instances`**. +- **`POWERSYNC_TARGET`** — Name of a target defined in `cli.yaml` (Cloud). Same as passing `--target`. - **`API_URL`** — Self-hosted PowerSync API base URL (e.g. `https://powersync.example.com`). Example (Cloud): @@ -261,7 +274,7 @@ Example (Cloud): PS_ADMIN_TOKEN=your-token INSTANCE_ID=123 powersync status ``` -See [docs/usage.md](../docs/usage.md) for full usage and resolution order (flags, env, cli.yaml). +See [docs/usage.md](../docs/usage.md) for full usage and resolution order (flags, cli.yaml, env). # Commands @@ -374,7 +387,7 @@ _See code: [@oclif/plugin-commands](https://github.com/oclif/plugin-commands/blo ``` USAGE - $ powersync compact [--directory ] [--instance-id ] [--timeout ] + $ powersync compact [--directory ] [--target | --instance-id ] [--timeout ] FLAGS --timeout= [default: 30] Maximum time to wait for compaction to complete, in minutes. Use 0 to wait @@ -387,6 +400,7 @@ PROJECT FLAGS CLOUD_PROJECT FLAGS --instance-id= PowerSync Cloud instance ID. Manually passed if the current context has not been linked. + --target= Name of a target defined in cli.yaml to run against. Resolved: flag → POWERSYNC_TARGET. DESCRIPTION [Cloud only] Compact the linked Cloud instance. @@ -429,8 +443,8 @@ _See code: [src/commands/configure/ide.ts](https://github.com/powersync-ja/power ``` USAGE - $ powersync deploy [--deploy-timeout ] [--dry-run] [--directory ] [--instance-id ] - [--sync-config-file-path ] [--skip-validations | --validate-only ] + $ powersync deploy [--deploy-timeout ] [--dry-run] [--directory ] [--target | + --instance-id ] [--sync-config-file-path ] [--skip-validations | --validate-only ] FLAGS --deploy-timeout= [default: 300] Seconds to wait after scheduling a deploy before timing out while polling @@ -451,6 +465,7 @@ PROJECT FLAGS CLOUD_PROJECT FLAGS --instance-id= PowerSync Cloud instance ID. Manually passed if the current context has not been linked. + --target= Name of a target defined in cli.yaml to run against. Resolved: flag → POWERSYNC_TARGET. DESCRIPTION [Cloud only] Deploy local config to the linked Cloud instance (connections + auth + sync config). @@ -477,8 +492,8 @@ _See code: [src/commands/deploy/index.ts](https://github.com/powersync-ja/powers ``` USAGE - $ powersync deploy service-config [--deploy-timeout ] [--dry-run] [--directory ] [--instance-id ] - [--skip-validations | --validate-only ] + $ powersync deploy service-config [--deploy-timeout ] [--dry-run] [--directory ] [--target | + --instance-id ] [--skip-validations | --validate-only ] FLAGS --deploy-timeout= [default: 300] Seconds to wait after scheduling a deploy before timing out while polling @@ -497,6 +512,7 @@ PROJECT FLAGS CLOUD_PROJECT FLAGS --instance-id= PowerSync Cloud instance ID. Manually passed if the current context has not been linked. + --target= Name of a target defined in cli.yaml to run against. Resolved: flag → POWERSYNC_TARGET. DESCRIPTION [Cloud only] Deploy only local service config to the linked Cloud instance. @@ -520,8 +536,8 @@ _See code: [src/commands/deploy/service-config.ts](https://github.com/powersync- ``` USAGE - $ powersync deploy sync-config [--deploy-timeout ] [--dry-run] [--directory ] [--instance-id ] - [--sync-config-file-path ] [--skip-validations | ] + $ powersync deploy sync-config [--deploy-timeout ] [--dry-run] [--directory ] [--target | + --instance-id ] [--sync-config-file-path ] [--skip-validations | ] FLAGS --deploy-timeout= [default: 300] Seconds to wait after scheduling a deploy before timing out while polling @@ -540,6 +556,7 @@ PROJECT FLAGS CLOUD_PROJECT FLAGS --instance-id= PowerSync Cloud instance ID. Manually passed if the current context has not been linked. + --target= Name of a target defined in cli.yaml to run against. Resolved: flag → POWERSYNC_TARGET. DESCRIPTION [Cloud only] Deploy only local sync config to the linked Cloud instance. @@ -563,7 +580,7 @@ _See code: [src/commands/deploy/sync-config.ts](https://github.com/powersync-ja/ ``` USAGE - $ powersync destroy [--directory ] [--instance-id ] [--confirm yes] + $ powersync destroy [--directory ] [--target | --instance-id ] [--confirm yes] FLAGS --confirm=