Skip to content

feat: Added compact command#41

Open
michaelbarnes wants to merge 2 commits into
mainfrom
feat/compact-command
Open

feat: Added compact command#41
michaelbarnes wants to merge 2 commits into
mainfrom
feat/compact-command

Conversation

@michaelbarnes
Copy link
Copy Markdown

This PR introduces the compact command to the CLI allowing developers to run compact jobs on demand via the CLI.

Usage

powersync compact
# or with explicit IDs (no link required):
powersync compact --instance-id <id> --project-id <project> --org-id <org>

Implementation

The command is modeled directly on powersync destroy:

  • Extends CloudInstanceCommand, so it reuses the existing instance/project/org resolution from cli.yaml, flags, or env vars.
  • Calls client.compact({ org_id, app_id, id }).
  • If the response includes an operation_id, polls via waitForOperationStatusChange with a 30-minute timeout (longer than destroy's 10 min, since compaction can run long on large buckets). If the response has no operation_id, treats the call as immediately complete.
  • Reports Instance compacted successfully, on success, or directs users to powersync status for diagnostics on failure.

This is a Cloud-only command.

Tests

Added cli/test/commands/compact.test.ts covering:

  • success path (with and without operation_id in the response)
  • polling reports failed status
  • network/client error
  • missing-link (no cli.yaml) and self-hosted project rejection

All 127 tests in the CLI suite pass.

Incidental cleanup

Fixed two pre-existing lint errors in cli/test/commands/migrate.test.ts that were blocking the pre-commit hook:

  • Wrapped the top-level test() in a describe('migrate', () => { it(...) }) to clear
    mocha/no-global-tests.
  • Changed 'utf-8' → 'utf8' to clear unicorn/text-encoding-identifier-case.

AI Disclaimer

Claude Opus 4.7 assisted in the development of this feature.

Copy link
Copy Markdown
Collaborator

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with these changes :)

instanceId: linked.instance_id,
linked,
operationId: compactResult.operation_id,
timeoutMs: 30 * 60 * 1000
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compact operations can generally take quite some time. For that reason, I can see many more potential occurrences for this command to timeout - compared to the deploy command which is a less likely to timeout in a standard timeframe. I think it could be nice to potentially make this timeout configurable with an optional input flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants