Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/akuna-storage-org.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sawala/cli": minor
---

Add `sawala akuna storage status` and `sawala akuna storage isolate` — org-level data residency. `isolate` enables a dedicated database for the whole org (moves all BYO connections onto it, new BYO connections inherit it; managed stays shared); `status` shows current residency. Org-level counterpart to the per-connection `akuna connection isolate` primitive.
64 changes: 64 additions & 0 deletions packages/sawala/src/commands/akuna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { confirmOrThrow } from '../lib/io'
*/

const CONNECTIONS = '/cli/akuna/connections'
const STORAGE = '/cli/akuna/storage'

interface Connection {
id: string
Expand All @@ -38,6 +39,16 @@ interface ProvisionResult {
isolatedDbId: string
}

// Org-level data-residency status. Isolation is an ORG setting (per-product):
// enabling moves ALL the org's BYO connections onto one dedicated database.
// Managed (Quick Login) connections always stay shared and are not counted.
interface StorageStatus {
isolated: boolean
databaseName: string | null
byoTotal: number
byoIsolated: number
}

function printJson(value: unknown): void {
process.stdout.write(JSON.stringify(value, null, 2) + '\n')
}
Expand Down Expand Up @@ -102,5 +113,58 @@ export function createAkunaCommand(): Command {
})

akuna.addCommand(connection)

// ── Org-level data residency (the primary model) ────────────────────────────
// Isolation is an ORG setting: `storage isolate` moves ALL the org's BYO
// connections onto one dedicated per-org database, and new BYO connections
// inherit it. This is the org-level counterpart to the per-connection
// `connection isolate` primitive above. Managed connections always stay shared.
const storage = new Command('storage').description(
"Manage the org's data residency (dedicated database for all BYO connections).",
)

storage
.command('status')
.description('Show whether the org uses a dedicated database, and how many BYO connections are on it.')
.action(async () => {
const ctx = await orgCtx()
const s = await apiFetch<StorageStatus>(ctx, STORAGE)
if (!s.isolated) {
process.stdout.write(`Shared storage. ${s.byoTotal} BYO connection(s) in the org.\n`)
return
}
process.stdout.write(
`Dedicated database active (${s.databaseName}). ${s.byoIsolated} of ${s.byoTotal} BYO connection(s) on it; new BYO connections inherit it.\n`,
)
})

storage
.command('isolate')
.description(
'Enable a dedicated database for the whole org: move ALL BYO connections onto ' +
'it (managed connections stay shared) and auto-isolate future BYO connections. ' +
'Idempotent. NOTE: effectively one-way — no isolated→shared migration. Requires --yes or a TTY.',
)
.option('-y, --yes', 'Skip the confirmation prompt.')
.option('--dry-run', 'Print what would be sent without writing.')
.action(async (opts: { yes?: boolean; dryRun?: boolean }) => {
const ctx = await orgCtx()
const path = `${STORAGE}/isolate`
if (opts.dryRun) {
printJson({ wouldSend: { method: 'POST', path } })
return
}
if (!opts.yes) {
await confirmOrThrow(
'Enable a dedicated database for this org? All BYO connections move onto it. This is effectively one-way.',
)
}
const s = await apiFetch<StorageStatus>(ctx, path, { method: 'POST', body: {} })
process.stdout.write(
`Dedicated database enabled (${s.databaseName}). ${s.byoIsolated} of ${s.byoTotal} BYO connection(s) on it.\n`,
)
})

akuna.addCommand(storage)
return akuna
}
Loading