@somewhere-cloud/cli 0.38.155 → 0.38.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/commands/docs.js +1 -1
  3. package/dist/lib/bundle.js +286 -188
  4. package/dist/lib/bundle.js.map +3 -3
  5. package/npm-shrinkwrap.json +2 -2
  6. package/package.json +2 -3
  7. package/dist/docs/adopt.md +0 -39
  8. package/dist/docs/analytics.md +0 -161
  9. package/dist/docs/api-reference.md +0 -339
  10. package/dist/docs/api-surface.md +0 -2067
  11. package/dist/docs/app-mcp.md +0 -162
  12. package/dist/docs/architecture-patterns.md +0 -334
  13. package/dist/docs/auth-client.md +0 -531
  14. package/dist/docs/billing.md +0 -76
  15. package/dist/docs/browser.md +0 -639
  16. package/dist/docs/calendar.md +0 -298
  17. package/dist/docs/changes.md +0 -323
  18. package/dist/docs/cli.md +0 -407
  19. package/dist/docs/common-mistakes.md +0 -199
  20. package/dist/docs/connect-agent.md +0 -72
  21. package/dist/docs/cors.md +0 -114
  22. package/dist/docs/cron.md +0 -167
  23. package/dist/docs/database-engine.md +0 -167
  24. package/dist/docs/declared-data.md +0 -1656
  25. package/dist/docs/declared-files.md +0 -475
  26. package/dist/docs/deploy-intelligence.md +0 -188
  27. package/dist/docs/deploy.md +0 -733
  28. package/dist/docs/design-system.md +0 -273
  29. package/dist/docs/dev-environments.md +0 -496
  30. package/dist/docs/domain-ownership.md +0 -31
  31. package/dist/docs/domains.md +0 -370
  32. package/dist/docs/feedback.md +0 -88
  33. package/dist/docs/file-tools.md +0 -116
  34. package/dist/docs/functions.md +0 -489
  35. package/dist/docs/getting-started.md +0 -238
  36. package/dist/docs/github.md +0 -95
  37. package/dist/docs/google-calendar.md +0 -212
  38. package/dist/docs/groups.md +0 -836
  39. package/dist/docs/guarantees.md +0 -58
  40. package/dist/docs/handled-for-you.md +0 -224
  41. package/dist/docs/inspect.md +0 -171
  42. package/dist/docs/limits.md +0 -68
  43. package/dist/docs/live-data.md +0 -197
  44. package/dist/docs/live.md +0 -92
  45. package/dist/docs/local-dev.md +0 -30
  46. package/dist/docs/migration-supabase.md +0 -58
  47. package/dist/docs/payments.md +0 -1102
  48. package/dist/docs/portability.md +0 -194
  49. package/dist/docs/postgres.md +0 -301
  50. package/dist/docs/pricing-comparison.md +0 -42
  51. package/dist/docs/pricing.md +0 -39
  52. package/dist/docs/project-groups.md +0 -107
  53. package/dist/docs/projects.md +0 -380
  54. package/dist/docs/recipe-ai-agent.md +0 -112
  55. package/dist/docs/recipe-ai-features.md +0 -227
  56. package/dist/docs/recipe-ai-receipts.md +0 -783
  57. package/dist/docs/recipe-background-jobs.md +0 -369
  58. package/dist/docs/recipe-booking.md +0 -348
  59. package/dist/docs/recipe-csv-import.md +0 -390
  60. package/dist/docs/recipe-ecommerce.md +0 -127
  61. package/dist/docs/recipe-email.md +0 -282
  62. package/dist/docs/recipe-escalation.md +0 -133
  63. package/dist/docs/recipe-file-uploads.md +0 -159
  64. package/dist/docs/recipe-import-app.md +0 -110
  65. package/dist/docs/recipe-login.md +0 -457
  66. package/dist/docs/recipe-multi-chat.md +0 -198
  67. package/dist/docs/recipe-paid-api.md +0 -161
  68. package/dist/docs/recipe-pdfs.md +0 -205
  69. package/dist/docs/recipe-push-notifications.md +0 -107
  70. package/dist/docs/recipe-seo.md +0 -200
  71. package/dist/docs/recipe-signed-in-app.md +0 -330
  72. package/dist/docs/render.md +0 -99
  73. package/dist/docs/rooms.md +0 -554
  74. package/dist/docs/sdk.md +0 -287
  75. package/dist/docs/sdks.md +0 -24
  76. package/dist/docs/search.md +0 -199
  77. package/dist/docs/security-model.md +0 -168
  78. package/dist/docs/setup.md +0 -212
  79. package/dist/docs/smoke.md +0 -102
  80. package/dist/docs/speed.md +0 -298
  81. package/dist/docs/sql-compatibility.md +0 -96
  82. package/dist/docs/sw.agent.md +0 -248
  83. package/dist/docs/sw.ai.md +0 -1291
  84. package/dist/docs/sw.auth.md +0 -1811
  85. package/dist/docs/sw.billing.md +0 -171
  86. package/dist/docs/sw.db.md +0 -2128
  87. package/dist/docs/sw.email.md +0 -661
  88. package/dist/docs/sw.endpoint.md +0 -187
  89. package/dist/docs/sw.env.md +0 -303
  90. package/dist/docs/sw.fetch.md +0 -115
  91. package/dist/docs/sw.fs.md +0 -424
  92. package/dist/docs/sw.groups.md +0 -836
  93. package/dist/docs/sw.image.md +0 -69
  94. package/dist/docs/sw.jobs.md +0 -520
  95. package/dist/docs/sw.logs.md +0 -61
  96. package/dist/docs/sw.mail.md +0 -106
  97. package/dist/docs/sw.notifications.md +0 -78
  98. package/dist/docs/sw.push.md +0 -161
  99. package/dist/docs/sw.rateLimit.md +0 -67
  100. package/dist/docs/sw.web.md +0 -128
  101. package/dist/docs/tasks.md +0 -269
  102. package/dist/docs/test.md +0 -220
  103. package/dist/docs/tool-reference-account.md +0 -7
  104. package/dist/docs/tool-reference-ai.md +0 -121
  105. package/dist/docs/tool-reference-analytics.md +0 -37
  106. package/dist/docs/tool-reference-api.md +0 -19
  107. package/dist/docs/tool-reference-artifacts.md +0 -35
  108. package/dist/docs/tool-reference-auth.md +0 -163
  109. package/dist/docs/tool-reference-browser.md +0 -114
  110. package/dist/docs/tool-reference-code.md +0 -26
  111. package/dist/docs/tool-reference-connect.md +0 -21
  112. package/dist/docs/tool-reference-cron.md +0 -48
  113. package/dist/docs/tool-reference-db.md +0 -282
  114. package/dist/docs/tool-reference-domains.md +0 -107
  115. package/dist/docs/tool-reference-email.md +0 -55
  116. package/dist/docs/tool-reference-env.md +0 -19
  117. package/dist/docs/tool-reference-feedback.md +0 -56
  118. package/dist/docs/tool-reference-fs.md +0 -265
  119. package/dist/docs/tool-reference-github.md +0 -57
  120. package/dist/docs/tool-reference-groups.md +0 -85
  121. package/dist/docs/tool-reference-help.md +0 -29
  122. package/dist/docs/tool-reference-jobs.md +0 -39
  123. package/dist/docs/tool-reference-live.md +0 -48
  124. package/dist/docs/tool-reference-logs.md +0 -16
  125. package/dist/docs/tool-reference-payments.md +0 -44
  126. package/dist/docs/tool-reference-project.md +0 -706
  127. package/dist/docs/tool-reference-push.md +0 -78
  128. package/dist/docs/tool-reference-rate-limit.md +0 -18
  129. package/dist/docs/tool-reference-search.md +0 -68
  130. package/dist/docs/tool-reference-security.md +0 -42
  131. package/dist/docs/tool-reference-smoke.md +0 -17
  132. package/dist/docs/tool-reference-stock-photos.md +0 -20
  133. package/dist/docs/tool-reference-tasks.md +0 -73
  134. package/dist/docs/tool-reference-telegram.md +0 -32
  135. package/dist/docs/tool-reference-usage.md +0 -9
  136. package/dist/docs/tool-reference-web.md +0 -71
  137. package/dist/docs/tool-reference-webhooks.md +0 -9
  138. package/dist/docs/troubleshooting.md +0 -411
  139. package/dist/docs/typed-functions.md +0 -94
  140. package/dist/docs/verify-before-deploy.md +0 -67
  141. package/dist/docs/vs-supabase.md +0 -75
  142. package/dist/docs/vs-vercel.md +0 -103
@@ -1,194 +0,0 @@
1
- # Portability — getting your data out
2
-
3
- Your data and code are yours. There are four exits, each in an ordinary format:
4
-
5
- 1. **Source:** `somewhere pull <project-id-or-subdomain>` or
6
- `project_export({ project_id })` returns the live release's files.
7
- 2. **SQL dump:** `somewhere db dump --output backup.sql` or `db_dump({ project_id })`
8
- writes the raw SQL database's schema and rows as one `.sql` file, up to
9
- 1,000,000 rows per table.
10
- 3. **CSV export:** `db_export` returns one raw SQL table as CSV, up to
11
- 100,000 rows per response; filter to collect more.
12
- 4. **Your own PostgreSQL:** attach a database in your own Neon account and
13
- query it as `sw.postgres` (`postgres` topic); attaching moves no existing data.
14
-
15
- For a managed table, use `db_browse` with `plane: "managed"` or run
16
- `somewhere db rows <table>`.
17
- Uploaded files come out through `fs_read`, and app users through
18
- `GET /v1/auth/users/inventory`. Password credentials cannot be exported; users
19
- set a password in the new app.
20
-
21
- To host elsewhere, keep your React and TypeScript source and replace each
22
- platform service and generated browser client your code calls — auth, data, files, email, AI and the rest
23
- — with the service you choose. Exporting the database moves your rows; it
24
- does not replace `sw.*`.
25
-
26
- ## Full database dump
27
-
28
- In an MCP client, call `db_dump({ project_id: "my-app" })`. For a local
29
- backup, start in a new directory so existing backups remain untouched.
30
-
31
- ```bash
32
- # In a new backup directory, via the CLI
33
- somewhere db dump --output backup.sql
34
-
35
- # Via curl — -D keeps the response headers, which carry the capture receipt
36
- curl --fail --show-error -X POST https://api.somewhere.cloud/v1/db/dump \
37
- -H "Authorization: Bearer $SOMEWHERE_API_KEY" \
38
- -H "Content-Type: application/json" \
39
- -d '{"project_id":"my-app"}' \
40
- -D dump-headers.txt -o backup.sql
41
- ```
42
-
43
- The file holds the schema (CREATE TABLE / INDEX / TRIGGER), every row as
44
- INSERT statements, sequence state, and a transaction wrapper. Schema, rows and
45
- sequence state come from the same captured read.
46
-
47
- **Check the file.** When the API returns a capture receipt, `db_dump` checks it for you: it recomputes the SQL hash
48
- over the bytes it received and the policy hash over the labels it parsed, and
49
- on any mismatch returns `DUMP_INTEGRITY_UNCONFIRMED` (502) and no SQL. With
50
- curl, compare `sql_sha256` in the `X-Dump-Capture` header with
51
- `shasum -a 256 backup.sql`. On Linux use `sha256sum backup.sql`. The CLI writes the SQL without the
52
- receipt; use MCP or curl when you need to compare the downloaded bytes with
53
- the capture. Treat a failed or interrupted download as incomplete.
54
-
55
- **Restore.** The file restores directly into the source database engine:
56
-
57
- ```bash
58
- sqlite3 backup.db < backup.sql
59
- ```
60
-
61
- For another database engine, convert the schema and data for that destination.
62
- Review the dialect differences in `sql-compatibility`, then verify queries
63
- and access rules as described in https://somewhere.cloud/migration.txt.
64
-
65
- **Re-declare access.** Table-access declarations and sensitive-column marks
66
- are platform policy, not SQL. Their labels travel as comment lines in the SQL
67
- preamble, and `db_dump` returns them as `excluded_security_policy.policies`
68
- (a warning appears only when the list is non-empty). A SQL restore never
69
- applies them. Re-declare them in the destination system. For a managed Somewhere project,
70
- declare them in `db/schema.ts` and deploy, then inspect them with `db_scope_list`. An empty list means this capture found no table-access
71
- declarations. Member join definitions and handler authorization need separate
72
- configuration and checks.
73
-
74
- **Limits.** Each table can hold up to 1,000,000 rows in a dump.
75
- A table over the limit stops the whole dump; there is no option to skip it.
76
- Export tables individually as CSV, filter large tables into smaller ranges,
77
- and recreate their schema from `db/schema.ts` or `db_describe`. Full-text (FTS5) tables with internally stored content — including
78
- the platform's file search index — are captured with their declared options,
79
- configuration and contents and restore into a fresh database with MATCH
80
- intact. `sw.db.dump()` is not available inside a deployed function;
81
- exporting the whole database requires developer credentials.
82
-
83
- ### If the dump is refused
84
-
85
- A refused capture returns an error instead of SQL. Check the command exit
86
- status before using a downloaded file.
87
-
88
- - **Retry** — the database moved or could not be read during the capture:
89
- `DUMP_SCHEMA_CHANGED` (409), `DUMP_SOURCE_CHANGED` (409, the owner or
90
- database changed), `DUMP_CAPTURE_UNCONFIRMED` (503),
91
- `DUMP_SCHEMA_UNAVAILABLE` (503, table metadata could not be verified),
92
- `DUMP_POLICY_UNAVAILABLE` (503, table-access declarations could not be read).
93
- - **Too large for one dump** — the whole dump is refused; export tables
94
- individually as CSV and recreate their schema:
95
- `DUMP_ROW_LIMIT_EXCEEDED` (413, a table above 1,000,000 rows),
96
- `DUMP_CAPTURE_LIMIT_EXCEEDED` (413, the capture exceeds the supported query size or column count).
97
- - **Fix first** — `DATABASE_NOT_INITIALIZED` (409: the project has no
98
- database yet; the dump never creates one), `DUMP_POLICY_INVALID` (422:
99
- table-access declarations are invalid), `DUMP_UNSUPPORTED_SCHEMA` (422:
100
- external-content or contentless full-text tables, other virtual-table
101
- modules, or sequence state the dump cannot preserve).
102
-
103
- ### The capture receipt
104
-
105
- The receipt lets you prove later which bytes this capture produced. The REST
106
- response carries it in the `X-Dump-Capture` header and `db_dump` returns it
107
- as `excluded_security_policy.capture` (v1). It holds identity, hashes and
108
- times only — never the labels: the canonical `project_id` and
109
- `database_id`, `sql_sha256` / `schema_sha256` / `policy_sha256`, and
110
- `policy_observed_at`, `data_observation_started_at`,
111
- `data_observation_completed_at`, `binding_checked_at`.
112
-
113
- `sql_sha256` covers the SQL bytes, `schema_sha256` the schema statements,
114
- and `policy_sha256` the policy labels. The times are separate observations:
115
- the database and the policy were each captured at their recorded time, and
116
- matching binding checks before and after mean the same project, owner and
117
- database were observed twice; they do not exclude a change between the
118
- observations. An absent receipt (an older API during a rolling release) means
119
- no capture-integrity evidence; the policy labels may still be present. A dump
120
- restores data and schema. Reapply and test the destination's access rules
121
- before serving users.
122
-
123
- ## Attaching PostgreSQL instead of leaving
124
-
125
- You do not have to move OUT to run PostgreSQL. A project can attach one
126
- external PostgreSQL database — a Neon database in your own Neon account, paid
127
- for by you — and query it from your functions as `sw.postgres`.
128
- `docs({ topic: 'postgres' })` is the contract.
129
-
130
- You own the account, billing and authorization decisions. Declared row
131
- permissions apply to the managed database; queries through the external
132
- driver use the permissions you implement. Attaching a database does not
133
- move existing data into it.
134
-
135
- ## One table as CSV
136
-
137
- Call `db_export({ project_id: "my-app", table: "orders" })` with the full MCP
138
- tool set, or use `POST /v1/db/export` with developer credentials. The hosted
139
- connectors do not include this tool.
140
-
141
- Each response contains up to 100,000 rows. A response at
142
- the cap is marked `truncated`; narrow `filters` (the `db_browse` shape)
143
- until it is clear. Use disjoint ranges to collect a large table. Rows have no
144
- guaranteed order, so an unfiltered capped response is not the first page of a
145
- complete export.
146
-
147
- ## File storage
148
-
149
- Call `fs_read({ project_id: "my-app", path: "/" })` to list a directory.
150
- Pass a file path to read that file.
151
-
152
- ## Source code
153
-
154
- ```bash
155
- somewhere pull <project-id-or-subdomain> --out my-app # Use a new folder
156
- ```
157
-
158
- `pull` downloads the live release's source and adds a `tsconfig.json` and
159
- `package.json` (only where absent) for local typechecking. Edit and run
160
- `somewhere deploy` to publish again.
161
-
162
- The source is TypeScript with no required framework. To run it elsewhere,
163
- replace `sw.*` services, generated `somewhere:data`, `somewhere:files` and
164
- `somewhere:api` clients, and the access rules in `db/schema.ts` with your
165
- own services and checks. Add a build for the destination, such as Vite. https://somewhere.cloud/migration.txt lists what to provide for each service
166
- on the destination.
167
-
168
- ## App-user inventory and profiles
169
-
170
- Use `GET /v1/auth/users/inventory?project_id=<project>` with a developer
171
- key and follow `next_cursor` through every page. Compare the collected IDs
172
- with `total`; each page also carries its own checksum. The project's
173
- `auth_users` table is a copy for joins and can be incomplete.
174
-
175
- For profiles, pass those IDs to `GET /v1/auth/users` in batches of up to
176
- 200, using its `ids` query parameter. It returns
177
- roles, display names and metadata as well as account identity.
178
-
179
- ## End-user accounts
180
-
181
- For a signed-in user's own data export, use `GET /v1/auth/users/me/export`.
182
- The old `POST /v1/auth/export/request` and `POST /v1/auth/export/download`
183
- routes both return 501 `AUTH_FEATURE_UNAVAILABLE`.
184
-
185
- Passwords do not move with the app. Users set a password in the new app.
186
-
187
- ## What does not move
188
-
189
- - The somewhere.site subdomain (`<your-app>.somewhere.site`). Custom domains
190
- do (you own the DNS).
191
- - The dashboard and security-review surfaces — they are platform
192
- features; your data and code move.
193
-
194
- Related: `sw.db`, `security-model`, `sql-compatibility`, `postgres`.
@@ -1,301 +0,0 @@
1
- # PostgreSQL
2
-
3
- Attach one PostgreSQL database that you own to a project, then query it from
4
- your deployed functions as `sw.postgres`. The provider is Neon. You keep the
5
- Neon account and Neon bills you directly. Attaching works on every plan.
6
-
7
- The steps below use `jq` to build request bodies.
8
-
9
- ## Connect and attach
10
-
11
- Create a Neon API key in your Neon account. The CLI reads it from
12
- `SOMEWHERE_NEON_API_KEY`, stdin or a hidden prompt, never from an argument.
13
-
14
- ```bash
15
- # Set NEON_PROJECT_ID to your existing Neon project's ID.
16
- printf %s "$NEON_API_KEY" | somewhere postgres connect --project my-app --neon-project "$NEON_PROJECT_ID"
17
- somewhere postgres attach "$NEON_PROJECT_ID" --project my-app
18
- ```
19
-
20
- To start with a new database instead, run `somewhere postgres create --project
21
- my-app` with an organization or account key. Neon bills you for it, and the
22
- default region is `aws-us-east-2` unless you pass `--region`.
23
-
24
- ## Separate application credentials
25
-
26
- ```bash
27
- somewhere api POST /v1/postgres/credentials/separate -d '{"project_id":"my-app"}'
28
- ```
29
-
30
- After this, deployed functions connect as a restricted role that can read and
31
- write table rows but cannot change the schema. Schema changes go through
32
- migrations. Details are in **Restricted application role** below.
33
-
34
- ## Create a table
35
-
36
- Keep migration SQL outside your app folder, so it is not deployed as a public
37
- file. Save this as `../my-app-migrations/0001_tickets.sql`:
38
-
39
- ```sql
40
- CREATE TABLE tickets (
41
- id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
42
- owner_id text NOT NULL,
43
- title text NOT NULL,
44
- status text NOT NULL DEFAULT 'open',
45
- created_at timestamptz NOT NULL DEFAULT now()
46
- );
47
- CREATE INDEX tickets_owner_status ON tickets (owner_id, status, created_at DESC);
48
- ```
49
-
50
- Apply it:
51
-
52
- ```bash
53
- jq -n --rawfile sql ../my-app-migrations/0001_tickets.sql \
54
- '{project_id: "my-app", target: "production", name: "0001_tickets", sql: $sql}' \
55
- | somewhere api POST /v1/postgres/migrations/apply --data-file -
56
- ```
57
-
58
- The restricted role created above can read and write the new table.
59
-
60
- ## Query from a function
61
-
62
- Derive the user from the verified session with `sw.auth.requireUser(req)`, and
63
- pass every value to SQL as a parameter. Your `WHERE` clause decides which rows
64
- the user can see.
65
-
66
- ```ts
67
- // api/tickets.ts
68
- export default async function (req: Request, sw: SomewhereRuntimeContext): Promise<Response> {
69
- const user = await sw.auth.requireUser(req); // 401 when not signed in
70
- const status = new URL(req.url).searchParams.get('status') ?? 'open';
71
-
72
- const tickets = await sw.postgres.query(
73
- 'SELECT id, title, status FROM tickets WHERE owner_id = $1 AND status = $2 ORDER BY created_at DESC LIMIT 50',
74
- [user.id, status],
75
- );
76
- return Response.json({ tickets });
77
- }
78
- ```
79
-
80
- Deploy with `somewhere deploy`. A deployed release keeps the connection it was
81
- built with, so deploy again after any connection change.
82
-
83
- `sw.postgres` is the callable that `neon(connectionString)` returns from
84
- `@neondatabase/serverless` 1.1.0, bound to your database.
85
- Its shapes, results and errors are the driver's:
86
-
87
- - A query resolves to an array of rows, and errors throw. There is no
88
- `{ data, error }` envelope.
89
- - The tagged-template form sends each interpolated value as a parameter.
90
- - `sw.postgres.transaction([...])` sends a list of statements in one round trip
91
- and applies them together. A failing statement makes the call throw and none
92
- of the list applies. Use it to batch independent reads, too.
93
- - The list is fixed before the call. Express read-then-write logic in SQL, with
94
- a conditional `UPDATE`, a CTE or `RETURNING`.
95
- - Each `query` call is its own request, so separate `BEGIN` and `ROLLBACK` calls
96
- undo nothing. Use `transaction([...])`.
97
- - The third argument of `query(text, params, options)` is the driver's options.
98
- It does not filter rows; the `WHERE` clause does.
99
- - `sw.postgres.unsafe(text)` splices text into a tagged template unparameterized. Use it
100
- only for SQL you wrote, never for a value.
101
-
102
- ---
103
-
104
- ## Restricted application role
105
-
106
- `POST /v1/postgres/credentials/separate` requires project owner access. It
107
- does the following:
108
-
109
- - Creates a login role with `NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION
110
- NOBYPASSRLS NOINHERIT`.
111
- - Grants it `SELECT`, `INSERT`, `UPDATE` and `DELETE` on tables in schema
112
- `public`, and usage of their sequences.
113
- - Grants it the same on tables and sequences the attached role creates in
114
- `public` later.
115
- - Logs in as the new role and confirms that it owns no objects and cannot run
116
- persistent DDL.
117
-
118
- The attached role becomes the migration credential, which deployed functions
119
- never receive. The attached role must be able to create roles. If existing
120
- grants would give the new role more than the above, the call fails with
121
- `POSTGRES_RUNTIME_ROLE_UNSAFE`. Review those existing grants in your database;
122
- the platform leaves them unchanged.
123
-
124
- Row-level security policies apply to the restricted role. The platform does
125
- not write policies or tell the database which app user is calling, so the
126
- authorization in your handler stays required.
127
-
128
- Re-check both credentials with `POST /v1/postgres/credentials/verify`. If a
129
- separation was interrupted, finish it with `POST /v1/postgres/credentials/recover`
130
- and body `{"project_id":"my-app","action":"finalize"}`, or discard it with
131
- `"action":"abandon"` after you have inspected and removed the role. No second
132
- login role is created for the same setup.
133
-
134
- ## Migrations
135
-
136
- Migrations need separated credentials. Each request applies one SQL file of up
137
- to 1 MiB, as the migration role, over a direct
138
- connection. Do not put `BEGIN`, `COMMIT` or `ROLLBACK` in the file.
139
-
140
- - **Ledger:** applied migrations are recorded in
141
- `_somewhere_migrations.history` in your database. Read it with
142
- `somewhere api GET "/v1/postgres/migrations/status?project_id=my-app&target=production"`.
143
- - **Re-applying:** re-applying an applied name with the same SQL returns its
144
- existing receipt. A failed migration is rolled back and can be applied again.
145
- Reusing a name with different SQL is refused with
146
- `POSTGRES_MIGRATION_CHANGED`.
147
- - **Unknown outcome:** if the connection ends before the platform can confirm the outcome, the migration is marked
148
- `POSTGRES_MIGRATION_UNCERTAIN`. Its SQL may have committed, and later
149
- migrations are refused until you inspect the database.
150
- - **Preview database:** use `"target": "preview"` to migrate the preview
151
- database instead.
152
-
153
- ## Preview databases
154
-
155
- A preview release receives only the preview database's connection. It never
156
- receives the production connection. If the project has no preview database,
157
- or the preview database is not ready or no longer matches the attached
158
- production credentials, `sw.postgres` in a preview throws
159
- `POSTGRES_NOT_ATTACHED`. Draft runs receive no connection.
160
-
161
- ```bash
162
- somewhere api POST /v1/postgres/preview -d '{"project_id":"my-app","action":"create"}'
163
- ```
164
-
165
- `create` makes one child branch of your production branch in your Neon account,
166
- which Neon bills to you.
167
-
168
- - **What it holds:** a full copy of production data at creation, including any
169
- personal data production holds. Writes to the preview database do not reach
170
- production.
171
- - **Binding:** deploy a preview after `create` to bind it.
172
- - **`reset`:** replaces the preview's data with production's current data.
173
- - **`delete`:** deletes exactly that branch.
174
- - **Data loss:** both `reset` and `delete` discard everything written to the
175
- preview.
176
-
177
- Creating one needs separated credentials and an attachment that records its
178
- branch. Previews themselves depend on your plan: check `preview_allowed` under
179
- `tiers[].limits` in `GET /v1/pricing`. Read the preview database's state with
180
- `somewhere api GET "/v1/postgres/preview?project_id=my-app"`.
181
-
182
- ## Copy your project database into PostgreSQL
183
-
184
- A project owner can copy the project database's tables into a new schema of
185
- the attached Neon database. The copy needs separated credentials. The project
186
- database keeps serving the app until you change your code to use
187
- `sw.postgres`.
188
-
189
- ```bash
190
- somewhere api POST /v1/postgres/copy/prepare -d '{"project_id":"my-app","schema":"app_copy"}' > copy-plan.json
191
- jq '{project_id: "my-app", plan: .plan}' copy-plan.json | somewhere api POST /v1/postgres/copy --data-file -
192
- somewhere api GET "/v1/postgres/copy/status?project_id=my-app&schema=app_copy"
193
- ```
194
-
195
- - **Prepare and copy:** `prepare` writes nothing. It returns the plan, the
196
- tables and the refusals. `copy` runs exactly that plan, or refuses when the
197
- source or destination changed since.
198
- - **Atomicity:** the copy runs in one transaction. A refusal, failure or
199
- timeout rolls it back. Only `POSTGRES_COPY_OUTCOME_UNCERTAIN` means it may
200
- have committed. In that case read the copy status. Retrying the same plan
201
- returns the saved receipt if it committed.
202
- - **Fidelity:** values are copied exactly, with primary keys, unique rules,
203
- foreign keys and `NOT NULL`. Supported defaults are translated, and integer
204
- row-id keys become identity columns.
205
- - CHECK rules, triggers, views, non-binary collations, unsupported defaults,
206
- virtual search tables and references to tables that are not copied refuse
207
- the copy.
208
- - Non-unique partial and expression indexes are listed, not recreated.
209
- - Platform tables and app user accounts and sessions are excluded and
210
- listed.
211
- - Rows written after the snapshot are not copied.
212
- - Later writes follow PostgreSQL semantics; the response lists the
213
- differences under `fidelity`.
214
- - **Access:** access rules are not copied. The new schema belongs to the
215
- migration role, and other roles cannot read it until you grant access; the
216
- receipt lists the administrative roles that still can. To query it from
217
- functions, grant the application role access or move the tables into
218
- `public`.
219
- - **Limits:** one copy holds up to 64 tables,
220
- 20,000 rows and 4 MiB of values,
221
- and must finish within 60 seconds.
222
-
223
- ## Where your functions run
224
-
225
- Functions run near the visitor by default. To ask for them to run closer to
226
- the database:
227
-
228
- ```bash
229
- somewhere api PATCH /v1/projects/<project-id> -d '{"placement":"near-data"}'
230
- ```
231
-
232
- Use the project's id here, not its slug. Change back with
233
- `"placement":"near-user"`.
234
-
235
- - **When it applies:** placement takes effect on the next deploy. If it cannot
236
- be applied, the deploy still succeeds, says so and retries on the next
237
- deploy. Static files stay at the edge. Placement is not a data-residency
238
- guarantee.
239
- - **Automatic placement:** if you have never set a placement, attaching sets
240
- `near-data` for releases that carry a database connection.
241
- - **Disconnect:** disconnecting undoes only a placement the attachment set.
242
- - **Status:** `somewhere postgres status --json` reports
243
- `function_placement.preference` and its `provenance` (`default`, `explicit`
244
- or `neon-attachment`).
245
-
246
- To choose, measure your own workload under each placement with the same data,
247
- indexes, statements and authorization `WHERE`. Report first and repeated
248
- requests separately, and report p50 and p95.
249
-
250
- ## Changing or removing the connection
251
-
252
- - **Disconnect unlinks; it never deletes.** `somewhere postgres disconnect`
253
- leaves your Neon project and data as they are, including a database the
254
- platform created. It keeps the stored API key unless you pass `--forget-key`.
255
- - **To cut off access, rotate the password in Neon.** Releases already deployed
256
- keep the credential they were built with. Attaching does not rotate it.
257
- - **Functions receive only the connection string.** It arrives as a secret
258
- binding that is not in `sw.env`. Your function code and its dependencies run
259
- with that role's authority. The Neon API key is used only by the attachment
260
- management calls, and no management call returns either credential.
261
- - **A function deleted from your source keeps serving** until you deploy with
262
- `--replace-functions`.
263
- - **Access:** the management routes are under `/v1/postgres/` and take a
264
- developer credential. Changes need project owner access. Status, migration
265
- status, copy status and preview status need editor access.
266
-
267
- ## Creating a database: no automatic retries
268
-
269
- Neon's create call has no idempotency key, so a retried create can make a
270
- second billed database. Each request makes one create attempt and never
271
- retries it, and parallel requests cannot both create.
272
-
273
- - **`POSTGRES_CREATE_UNCERTAIN`:** the outcome was unreadable, so a database
274
- may exist. Check your Neon account. Then attach it with
275
- `somewhere postgres attach <neon-project-id>`, or disconnect to clear the
276
- state.
277
- - **`POSTGRES_CREATE_IN_PROGRESS`:** an earlier create is unresolved. The error
278
- names the database, its start time and, when known, the Neon project id.
279
- Nothing expires this state. Wait if the create is still running. Otherwise
280
- attach the database if you find it, or disconnect once you have reconciled.
281
- - **Disconnecting during an unresolved create** returns the Neon project id (or
282
- name and start time) once, with `unresolved_note`. The database stays in your
283
- Neon account, billing, until you attach or delete it.
284
- - **`POSTGRES_CREATE_SUPERSEDED`:** the database was created, but the project
285
- changed during the create, so it was not attached. Its id is in the error.
286
-
287
- ## Errors
288
-
289
- | Code | Meaning and fix |
290
- |---|---|
291
- | `POSTGRES_NOT_ATTACHED` | No database, or the release predates the attachment. Attach, then deploy again. |
292
- | `POSTGRES_NOT_CONNECTED` | No API key stored. Run `somewhere postgres connect`. |
293
- | `POSTGRES_KEY_SCOPE_UNKNOWN` | The key cannot list projects. Pass `--neon-project` for a project-scoped key. |
294
- | `POSTGRES_PROVIDER_UNAUTHORIZED` | Neon refused the key. Store a valid key. |
295
- | `POSTGRES_PROVIDER_UNREACHABLE` | Neon could not be reached. The key was not stored. |
296
- | `POSTGRES_BRANCH_AMBIGUOUS`, `POSTGRES_DATABASE_AMBIGUOUS`, `POSTGRES_ROLE_AMBIGUOUS` | More than one candidate. Pass `--branch`, `--database` or `--role` to `attach`. |
297
- | `POSTGRES_CONNECTION_URI_INCOMPLETE` | Neon returned no password for that role. Choose another role. The platform never resets a role password. |
298
- | `POSTGRES_CREDENTIALS_NOT_SEPARATED` | Separate application credentials before migrations, preview databases or copy. |
299
-
300
- Related: `sw.db`, `sw.auth`, `security-model`, `database-engine`,
301
- `sql-compatibility`.
@@ -1,42 +0,0 @@
1
- # Pricing comparison — somewhere.cloud vs the stack
2
-
3
- You'd normally need a stack like:
4
-
5
- | Service | Typical cost | Replaced by |
6
- |---|---|---|
7
- | Vercel Pro | $20/mo | hosting + functions |
8
- | Supabase Pro| $25/mo | database + auth + storage |
9
- | Clerk | $25/mo + per-MAU | auth |
10
- | Resend | $20/mo (50k/mo) | email |
11
- | Pinecone | $70/mo (starter) | vector search |
12
- | Cron / queue | ~$10/mo (Upstash, etc) | background work |
13
- | **Total** | **~$170/mo + per-MAU** | one stack |
14
-
15
- ## What somewhere.cloud costs
16
-
17
- Read the [current plans and prices](https://somewhere.cloud/pricing.txt) or query
18
- the [live catalog](https://api.somewhere.cloud/v1/pricing). Every tier includes
19
- unlimited projects and deploys.
20
-
21
- ## What we do NOT charge for
22
-
23
- - **Bandwidth**: Bandwidth is included on every plan. We do not meter it or bill for it. Fair use applies: this covers normal traffic to your app's pages, functions and files.
24
- - **Build minutes**: unmetered. Vercel Pro is 6000 min/mo.
25
- - **End users**: no per-user fees. Read the auth user allowance for your plan
26
- in the live catalog. Clerk's $25 Pro tier caps at 5K MAUs,
27
- then $0.02 each.
28
- - Storage plan allowances carry no overage charges.
29
- - **An attached PostgreSQL database**: nothing, on any plan including Free.
30
- You attach a database in your own provider account and they bill you
31
- directly on their published pricing — we do not meter it, mark it up, or
32
- resell it. `docs({ topic: 'postgres' })`.
33
-
34
- ## Payments & AI — what we DO charge
35
-
36
- - **Payments**: Read the Stripe Connect platform fee in the live catalog or in
37
- each checkout response (`fee_percent`).
38
- - **AI**: the same all-in catalog rates apply on every tier, and every plan
39
- includes a managed-AI allowance; allowance and prepaid ordering plus request
40
- limits are published at /v1/pricing.
41
-
42
- Related: `billing`, `vs-supabase`, `vs-vercel`, `portability`.
@@ -1,39 +0,0 @@
1
- # Pricing
2
-
3
- Bandwidth is included on every plan. We do not meter it or bill for it.
4
- Fair use applies: this covers normal traffic to your app's pages, functions and files.
5
-
6
- Database, auth, functions, files, email and custom domains are included on every plan. Projects and deploys are unlimited. Paid plans add capacity and features.
7
-
8
- Prices are in USD per month. Database and file storage allowances are totals across your account.
9
-
10
- | Plan | Monthly price | Database storage | File storage | Auth users | Transactional emails / month |
11
- | --- | ---: | ---: | ---: | ---: | ---: |
12
- | Free | $0 | 500 MB | 5 GB | 1,000 | 4,500 |
13
- | Builder | $25 | 10 GB | 100 GB | Unlimited | 50,000 |
14
- | Pro | $50 | 25 GB | 250 GB | Unlimited | 100,000 |
15
- | Scale | $100 | 50 GB | 1 TB | Unlimited | 250,000 |
16
- | Enterprise | Custom | Custom | Custom | Custom | Custom |
17
-
18
- ### Plan allowances for file storage and outbound email
19
-
20
- On Free, reaching a limit stops new writes or sends until the next period or an upgrade. On paid plans, allowances are not hard stops: we warn you and your app keeps running, with no overage charges. Nothing is deleted, and nothing is charged without your say-so.
21
-
22
- Free file storage has no reset period. Deleting files yourself frees space. Technical limits and AI have separate rules. For paid AI, add to your prepaid balance. Automatic top-up applies only if you turn it on.
23
-
24
- Enterprise: contact us.
25
-
26
- See [what happens at each limit](https://somewhere.cloud/pricing.txt) for details.
27
-
28
- Managed data grows with your app; the platform handles storage. Your account allowance covers the total across projects. Authentication emails are quota-exempt; abuse protection still applies.
29
-
30
- ### Included allowances
31
-
32
- - **Free:** 10 scheduled jobs per project, minimum interval 5 minutes; 10 MB per upload; 10 browser sessions; managed AI included. Transactional email also has a 150 per-day limit.
33
- - **Builder:** 100 scheduled jobs per project, minimum interval 1 minutes; 250 MB per upload; 10 browser sessions; managed AI included.
34
- - **Pro:** 100 scheduled jobs per project, minimum interval 1 minutes; 250 MB per upload; 10 browser sessions; managed AI included.
35
- - **Scale:** 100 scheduled jobs per project, minimum interval 1 minutes; 250 MB per upload; 10 browser sessions; managed AI included.
36
-
37
- Payments through Stripe Connect have a 0.5% platform fee in addition to Stripe processing fees. Managed AI uses published model rates; see [AI billing](https://somewhere.cloud/docs/billing.txt).
38
-
39
- This table is generated from [the public pricing API](https://api.somewhere.cloud/v1/pricing) when the docs are published. Read that endpoint for live values, or [compare plans](https://somewhere.cloud/pricing).