sandcms 0.6.3 → 0.8.0

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 (175) hide show
  1. package/README.md +15 -11
  2. package/dist/admin/Account.svelte +2 -0
  3. package/dist/admin/Admin.svelte +21 -6
  4. package/dist/admin/AssetAttachment.svelte +9 -6
  5. package/dist/admin/AssetAttachment.svelte.d.ts +3 -1
  6. package/dist/admin/BlueprintFields.svelte +0 -3
  7. package/dist/admin/BlueprintFields.svelte.d.ts +0 -1
  8. package/dist/admin/Editor.svelte +5 -10
  9. package/dist/admin/Fields.svelte +2 -8
  10. package/dist/admin/Fields.svelte.d.ts +0 -1
  11. package/dist/admin/Gallery.svelte +221 -80
  12. package/dist/admin/Gallery.svelte.d.ts +0 -1
  13. package/dist/admin/Inbox.svelte +3 -2
  14. package/dist/admin/LinkField.svelte +0 -3
  15. package/dist/admin/LinkField.svelte.d.ts +0 -1
  16. package/dist/admin/MediaLibrary.svelte +10 -7
  17. package/dist/admin/MediaPicker.svelte +43 -35
  18. package/dist/admin/MediaPicker.svelte.d.ts +0 -1
  19. package/dist/admin/Navigation.svelte +13 -2
  20. package/dist/admin/Pages.svelte +195 -0
  21. package/dist/admin/Pages.svelte.d.ts +7 -0
  22. package/dist/admin/Shell.svelte +27 -5
  23. package/dist/admin/SortableList.svelte +82 -61
  24. package/dist/admin/SortableList.svelte.d.ts +3 -1
  25. package/dist/admin/ThemePicker.svelte +72 -0
  26. package/dist/admin/ThemePicker.svelte.d.ts +18 -0
  27. package/dist/admin/UploadButton.svelte +2 -1
  28. package/dist/admin/UploadProgress.svelte +24 -0
  29. package/dist/admin/UploadProgress.svelte.d.ts +7 -0
  30. package/dist/admin/Users.svelte +8 -3
  31. package/dist/admin/client.d.ts +3 -670
  32. package/dist/admin/client.js +2 -1
  33. package/dist/admin/components/ui/alert/alert.svelte.d.ts +3 -13
  34. package/dist/admin/components/ui/attachment/attachment-media.svelte.d.ts +3 -13
  35. package/dist/admin/components/ui/attachment/attachment.svelte.d.ts +6 -26
  36. package/dist/admin/components/ui/badge/badge.svelte.d.ts +7 -25
  37. package/dist/admin/components/ui/button/button.svelte.d.ts +15 -53
  38. package/dist/admin/components/ui/toggle/toggle.svelte.d.ts +6 -26
  39. package/dist/admin/generated/admin.css +823 -115
  40. package/dist/admin/navigation.d.ts +9 -0
  41. package/dist/admin/navigation.js +20 -1
  42. package/dist/admin/theme-context.d.ts +7 -0
  43. package/dist/admin/theme-context.js +3 -0
  44. package/dist/admin/theme.d.ts +7 -0
  45. package/dist/admin/theme.js +14 -0
  46. package/dist/admin/types.d.ts +3 -1
  47. package/dist/admin/uploads.d.ts +8 -1
  48. package/dist/admin/uploads.js +94 -16
  49. package/dist/blueprints/files.js +1 -0
  50. package/dist/blueprints/labels.d.ts +6 -0
  51. package/dist/blueprints/labels.js +14 -0
  52. package/dist/blueprints/load.js +16 -2
  53. package/dist/blueprints/types.d.ts +4 -1
  54. package/dist/cli/admin.d.ts +39 -0
  55. package/dist/cli/admin.js +95 -0
  56. package/dist/cli/backup.js +4 -4
  57. package/dist/cli/doctor.d.ts +10 -1
  58. package/dist/cli/doctor.js +98 -33
  59. package/dist/cli/email-test.d.ts +3 -0
  60. package/dist/cli/email-test.js +20 -0
  61. package/dist/cli/files.d.ts +2 -6
  62. package/dist/cli/files.js +12 -2
  63. package/dist/cli/index.js +401 -95
  64. package/dist/cli/rebaseline.d.ts +10 -0
  65. package/dist/cli/rebaseline.js +117 -0
  66. package/dist/cli/scaffold.js +8 -8
  67. package/dist/cli/setup.js +16 -26
  68. package/dist/cli/upgrade.js +34 -7
  69. package/dist/env.d.ts +26 -2
  70. package/dist/env.js +48 -6
  71. package/dist/notification-fields.js +2 -1
  72. package/dist/server/admin-load.d.ts +85 -5
  73. package/dist/server/admin-load.js +26 -1
  74. package/dist/server/api-access.d.ts +4 -0
  75. package/dist/server/api-access.js +15 -2
  76. package/dist/server/api-keys.d.ts +96 -0
  77. package/dist/server/api-keys.js +115 -0
  78. package/dist/server/api-pagination.d.ts +3 -0
  79. package/dist/server/api.js +21 -63
  80. package/dist/server/auth.d.ts +10 -9
  81. package/dist/server/cms.d.ts +63 -21
  82. package/dist/server/cms.js +64 -7
  83. package/dist/server/db/auto-migrate.d.ts +0 -4
  84. package/dist/server/db/auto-migrate.js +12 -3
  85. package/dist/server/db/legacy.d.ts +13 -0
  86. package/dist/server/db/legacy.js +60 -0
  87. package/dist/server/db/migration-data.js +2 -34
  88. package/dist/server/db/migrations/{0000_foundation.sql → 0000_baseline.sql} +120 -4
  89. package/dist/server/db/migrations/meta/0000_snapshot.json +578 -3
  90. package/dist/server/db/migrations/meta/_journal.json +2 -58
  91. package/dist/server/db/schema.d.ts +119 -2
  92. package/dist/server/db/schema.js +23 -9
  93. package/dist/server/db/store.d.ts +25 -2
  94. package/dist/server/db/store.js +90 -26
  95. package/dist/server/forms.js +2 -1
  96. package/dist/server/hooks.js +155 -81
  97. package/dist/server/media/contracts.d.ts +115 -0
  98. package/dist/server/media/contracts.js +12 -0
  99. package/dist/server/media/deletions.d.ts +2 -1
  100. package/dist/server/media/deletions.js +3 -3
  101. package/dist/server/media/delivery.js +7 -11
  102. package/dist/server/media/processor-child.d.ts +2 -0
  103. package/dist/server/media/processor-child.js +236 -0
  104. package/dist/server/media/processor.d.ts +51 -0
  105. package/dist/server/media/processor.js +135 -0
  106. package/dist/server/media/render-math.d.ts +24 -0
  107. package/dist/server/media/render-math.js +50 -0
  108. package/dist/server/media/runner.d.ts +30 -1
  109. package/dist/server/media/runner.js +418 -165
  110. package/dist/server/media/service.d.ts +53 -11
  111. package/dist/server/media/service.js +307 -98
  112. package/dist/server/media/storage.d.ts +5 -0
  113. package/dist/server/media/storage.js +279 -0
  114. package/dist/server/media/upload-ticket.d.ts +12 -0
  115. package/dist/server/media/upload-ticket.js +35 -0
  116. package/dist/server/media/verify.d.ts +64 -0
  117. package/dist/server/media/verify.js +201 -0
  118. package/dist/server/platform/http.d.ts +27 -0
  119. package/dist/server/platform/http.js +77 -0
  120. package/dist/server/platform/index.d.ts +52 -0
  121. package/dist/server/platform/index.js +98 -0
  122. package/dist/server/platform/snapshots.d.ts +18 -0
  123. package/dist/server/platform/snapshots.js +110 -0
  124. package/dist/server/platform/volume.d.ts +20 -0
  125. package/dist/server/platform/volume.js +60 -0
  126. package/docs/acceptance.md +7 -5
  127. package/docs/api.md +56 -4
  128. package/docs/cloudflare.md +26 -152
  129. package/docs/content.md +20 -5
  130. package/docs/deployment.md +222 -57
  131. package/docs/email.md +6 -0
  132. package/docs/forms.md +2 -2
  133. package/docs/media.md +94 -21
  134. package/docs/package.md +21 -18
  135. package/docs/plans/0.7-self-hosted.md +264 -0
  136. package/docs/releases.md +37 -1
  137. package/docs/upgrades.md +72 -9
  138. package/package.json +37 -44
  139. package/templates/Dockerfile +32 -0
  140. package/templates/integration.ts +26 -5
  141. package/templates/openship.json +9 -0
  142. package/templates/railpack.json +1 -1
  143. package/templates/sandcms/blueprints/files/image.yaml +1 -1
  144. package/templates/sandcms/config.yaml +1 -1
  145. package/dist/cli/cloudflare.d.ts +0 -8
  146. package/dist/cli/cloudflare.js +0 -135
  147. package/dist/server/db/migrations/0001_independent_password_resets.sql +0 -3
  148. package/dist/server/db/migrations/0002_email_failure_reason.sql +0 -1
  149. package/dist/server/db/migrations/0003_direct_r2_uploads.sql +0 -10
  150. package/dist/server/db/migrations/0004_agent_api_keys.sql +0 -38
  151. package/dist/server/db/migrations/0005_api_retention_and_pagination.sql +0 -3
  152. package/dist/server/db/migrations/0006_durable_media_deletion.sql +0 -7
  153. package/dist/server/db/migrations/0007_content_and_job_indexes.sql +0 -2
  154. package/dist/server/db/migrations/0008_search_text_cache.sql +0 -45
  155. package/dist/server/db/migrations/meta/0001_snapshot.json +0 -1197
  156. package/dist/server/db/migrations/meta/0002_snapshot.json +0 -1204
  157. package/dist/server/db/migrations/meta/0003_snapshot.json +0 -1281
  158. package/dist/server/db/migrations/meta/0004_snapshot.json +0 -1546
  159. package/dist/server/db/migrations/meta/0005_snapshot.json +0 -1572
  160. package/dist/server/db/migrations/meta/0006_snapshot.json +0 -1627
  161. package/dist/server/db/migrations/meta/0007_snapshot.json +0 -1643
  162. package/dist/server/db/migrations/meta/0008_snapshot.json +0 -1711
  163. package/dist/worker/index.d.ts +0 -10
  164. package/dist/worker/index.js +0 -460
  165. package/dist/worker/local.d.ts +0 -5
  166. package/dist/worker/local.js +0 -57
  167. package/dist/worker/source.d.ts +0 -2
  168. package/dist/worker/source.js +0 -31
  169. package/dist/worker/uploads.d.ts +0 -22
  170. package/dist/worker/uploads.js +0 -48
  171. package/templates/sandcms/worker/index.ts +0 -1
  172. package/templates/sandcms/worker/local.ts +0 -1
  173. package/templates/sandcms/worker/wrangler.jsonc +0 -6
  174. /package/dist/{worker → server/media}/svg.d.ts +0 -0
  175. /package/dist/{worker → server/media}/svg.js +0 -0
package/docs/releases.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Release notes
2
2
 
3
+ ## 0.8.0
4
+
5
+ This minor release makes deploys overlap safely, adds operator commands, a Pages screen and a site logo in the admin, and removes the Cloudflare Worker support deprecated in 0.7.0. Upgrading from 0.7.x needs a one-time `sandcms rebaseline` while the site is stopped, in a maintenance window of a few minutes; older sites upgrade with 0.7.x first. See the [0.8.0 upgrade checklist](upgrades.md#080-upgrade-checklist). The only migration is the new baseline `0000_baseline`; there is no other SQL migration. Stored data, sessions, media files and project-owned YAML are preserved.
6
+
7
+ **Breaking: new migration baseline.** The 0.5.0–0.7.x migrations `0000_foundation` through `0009_local_media` are replaced by one frozen baseline, `0000_baseline`, with the same schema. Existing 0.7.x databases are converted once with the new `sandcms rebaseline`, which copies every row into a database built from the baseline, verifies each table and keeps a safety copy; older databases are first upgraded with 0.7.x. Follow the [0.8.0 upgrade checklist](upgrades.md#080-upgrade-checklist).
8
+
9
+ Deploys now overlap safely on OpenShip, Dokploy and Coolify. Every later migration must keep the previous release working, or be marked `-- sandcms:breaking` and announced; `bun scripts/migrations.ts` refuses drops, renames, rebuilds and other risky statements that carry neither marker nor a reviewed `-- sandcms:compatible` note. A package started on a database with newer compatible migrations runs normally, so a restarted or rolled-back previous release keeps working; `backup`, `restore` and snapshots accept such databases. Table rebuilds generated by drizzle-kit no longer cascade-delete dependent rows or lose triggers: the runner keeps foreign keys off for the whole migration and restores triggers. See [compatible migrations](upgrades.md#compatible-migrations).
10
+
11
+ The generated `Dockerfile` probes health every 5 seconds with a two-minute budget, sets `SHUTDOWN_TIMEOUT=8` and `SANDCMS_AUTO_MIGRATE=true`, and the integration stops background work and exits after draining on SIGTERM, inside the 10-second stop timeout hosts use by default. New sites get an `openship.json` that seeds OpenShip's volume and readiness probe. A failing start no longer writes a new `before-migrate` copy on every retry. See [deploys](deployment.md#deploys) and [platform settings](deployment.md#platform-settings).
12
+
13
+ Adds `sandcms key create`, `key list` and `key revoke`, so an operator or an agent with shell access to the site can issue an API key without a browser session. `key create` prints only the secret on stdout, refuses owners who are not admins or editors or who still have a temporary password, and audits creation as `apikey.create`. There is no schema migration. See [API keys from the CLI](api.md#from-the-cli).
14
+
15
+ Adds operator commands for the server shell: `sandcms user list`, `user set-role`, `user remove` and `user sign-out [--all]`; `key revoke --email` to revoke every key of one user; `sandcms email test` to check SMTP settings; `sandcms forms export` for submission CSVs; and `sandcms media prune [--delete]` to free originals and old variant versions that no asset uses. `sandcms doctor`, `migrate --check`, `user list`, `key list` and `media prune` accept `--json`. The CLI gains `--version` and help for each command (`sandcms <command> --help`), reports unknown options and subcommands without a stack trace or prompt, and no longer creates an empty database file when a user command points at a missing database. Destructive commands ask for confirmation and require `--yes` when no terminal is attached. No migration or configuration change is required. See [users](deployment.md#users) and [freeing unused files](media.md#freeing-unused-files).
16
+
17
+ Replaces the collapsible **Pages** sidebar group with a single **Pages** link to a new Pages screen: a searchable, sortable table of every page with its path, status and last update, and a row menu to edit, preview, publish or unpublish. Pages with a custom `navigation.group` or `navigation: { group: false }` keep their sidebar entry and are also listed in the table. No migration or YAML change is required. See [Pages screen](content.md#pages-screen).
18
+
19
+ The admin sidebar shows the site's favicon instead of the first letter of the project name. The new optional `logo` setting in `config.yaml` chooses another image, or `false` keeps the letter. No migration or configuration change is required. See [site logo](content.md#site-logo).
20
+
21
+ **Removed:** the Cloudflare Worker support deprecated in 0.7.0: `sandcms media import-r2` with its `--worker-url` and `--worker-token-stdin` options, the `sandcms/worker` and `sandcms/worker/local` exports, the `createCMS({ workerUrl, workerToken })` options and the `SANDCMS_WORKER_URL` and `SANDCMS_WORKER_TOKEN` variables. Sites with media still in R2 finish the import with 0.7.x, which 0.8.0 requires before `rebaseline` anyway. `sandcms upgrade` updates the generated integration; customized integrations must stop reading the `SANDCMS_WORKER_*` variables, which are no longer declared, and leftover `sandcms/worker/` files no longer build. `media.workerUrl` in `sandcms/config.yaml` is still accepted and ignored, so existing configuration keeps loading. See [Cloudflare](cloudflare.md).
22
+
23
+ ## 0.7.0
24
+
25
+ This minor release removes Cloudflare from SandCMS. A site becomes one container with one persistent volume that holds the database, image originals, variants and hourly database snapshots, and runs on any Docker host. We recommend [Dokploy](https://dokploy.com) or [Openship](https://openship.io). Upgrading from 0.6.3 applies retained migration `0009_local_media` and needs a one-time import of R2 media in a short maintenance window; see the [0.7.0 upgrade checklist](upgrades.md#070-upgrade-checklist). Stored data, asset IDs, public image URLs and project-owned YAML are preserved.
26
+
27
+ Stores media on the site volume. Originals and variants are files under `SANDCMS_MEDIA_DIR` (default `media/` next to the database), written durably before the database records them. Width, height and variant ETags are stored in SQLite. Uploads are refused when free disk space or the new optional `media.maxStorage` quota would run out; usage appears in the admin and in `sandcms doctor`. See [media storage](media.md#storage).
28
+
29
+ Processes images with sharp in a child process, one image at a time, so a large decode cannot take down the web server. Each original is decoded once per batch. TIFF input is now accepted, `media.uploadLimit` may be raised to 500 MB, and the new `media.maxPixels` (default 100 MP) limits decoded size. Variant URLs, presets and the preset version are unchanged. **Behaviour changes:** animated GIF and WebP inputs are flattened to their first frame; metadata is stripped from variants except EXIF copyright and artist; HEIC remains unsupported. See [changes from Cloudflare processing](media.md#changes-from-cloudflare-processing-070).
30
+
31
+ Uploads go to the site in 8 MB chunks with a signed ticket, so reverse proxies need no raised limits. Uploads show progress, retry failed chunks and resume after interruptions or restarts. API clients use the same flow with a write key; the earlier single presigned PUT is gone. See [media uploads](api.md#media-uploads). Requests other than upload chunks are limited to 1 MB (`SANDCMS_REQUEST_LIMIT`); set `BODY_SIZE_LIMIT=10M`.
32
+
33
+ Adds platform features for single-container hosting: a `site-id` check against a volume shared by another project, refusal to create a production database outside a mounted volume, a `/_sandcms/health` liveness route, hourly verified snapshots in `backups/latest.sqlite`, pruning of `before-migrate` snapshots to the newest three, first-admin bootstrap from `SANDCMS_BOOTSTRAP_EMAIL`, and `SANDCMS_INDEXING=false` for preview sites. The site derives its origin from the request and redirects other hostnames to `SANDCMS_ORIGIN`, so a domain change needs a restart, not a rebuild; remove `paths.origin` from `vite.config.ts`. New sites get a `Dockerfile` with a `HEALTHCHECK`. Overlapping (zero-downtime) and stop-then-start deploys both work; background work coordinates through database leases. See [deployment](deployment.md).
34
+
35
+ Adds `sandcms media import-r2` to copy an existing site's originals and every ready variant from R2 through the old Worker, resumably and with a final verification; `sandcms media verify [--repair]` to find and fix media rows without files, for example after a restore; and `sandcms media rebuild --force` to re-encode existing variants with sharp under the same URLs. See [sites still on Cloudflare media](cloudflare.md#sites-still-on-cloudflare-media).
36
+
37
+ **Removed:** `sandcms worker update`, the Cloudflare prompt in setup, generated `sandcms/worker/*` files for new sites, and R2 direct-upload configuration. **Deprecated, kept through 0.7.x:** `createCMS({ workerUrl, workerToken })`, `media.workerUrl` (ignored), `SANDCMS_WORKER_URL` and `SANDCMS_WORKER_TOKEN` (read only by the import), and the `sandcms/worker` and `sandcms/worker/local` exports. The package adds a `sandcms/media-processor` export used by the processor child process; keep `sharp` in `ssr.external`.
38
+
3
39
  ## 0.6.3
4
40
 
5
41
  This patch release polishes the admin interface and adds user removal. There is no SQL migration, Worker protocol change or configuration change; upgrading from 0.6.2 only requires installing the package and rebuilding; see the [0.6.3 upgrade checklist](upgrades.md#063-upgrade-checklist). Stored data and project-owned YAML are preserved.
@@ -61,7 +97,7 @@ Upgrades the application and generated starters to SvelteKit 3.0.0, `@sveltejs/p
61
97
 
62
98
  Admin uploads now use metadata initialization, a 15-minute presigned PUT directly from the browser to private R2 staging, and idempotent completion. The website no longer buffers file bodies or stores new originals in SQLite. Durable finalization validates a private snapshot, preserves retry/restart recovery, and prevents a reused upload URL from replacing an accepted original.
63
99
 
64
- Run the retained `0003_direct_r2_uploads.sql` migration; it preserves existing media and pending legacy BLOB transfers. Deploy the protocol-4 Worker first (it also accepts protocol 3), configure bucket-scoped R2 signing credentials, PUT CORS for the admin origin, and a one-day `incoming/` lifecycle rule before deploying the website. The local Worker now uses `sandcms/worker/local.ts`. See [Cloudflare configuration](cloudflare.md#direct-upload-configuration).
100
+ Run the retained `0003_direct_r2_uploads.sql` migration; it preserves existing media and pending legacy BLOB transfers. Deploy the protocol-4 Worker first (it also accepts protocol 3), configure bucket-scoped R2 signing credentials, PUT CORS for the admin origin, and a one-day `incoming/` lifecycle rule before deploying the website. The local Worker now uses `sandcms/worker/local.ts`. See the 0.6 version of `docs/cloudflare.md`.
65
101
 
66
102
  Fixes large raster uploads failing with “file too large” during dimension inspection. Upload validation and legacy-original rebuilds now use remote JSON metadata transforms instead of `IMAGES.info()`. New originals retain their dimensions in R2 metadata for variant generation. The 100 MB / 100 MP limits and private originals remain unchanged. Deploy with `sandcms worker update`; the `IMAGES` binding is no longer required.
67
103
 
package/docs/upgrades.md CHANGED
@@ -1,5 +1,66 @@
1
1
  # Updates and generated files
2
2
 
3
+ ## 0.8.0 upgrade checklist
4
+
5
+ Version 0.8.0 replaces the 0.5.0–0.7.x migration history (`0000_foundation` through `0009_local_media`) with a new frozen baseline, `0000_baseline`, so that every later release can deploy by overlap. The schema is the same; existing databases are converted once with `sandcms rebaseline`, which copies every row into a database built from the new baseline. Plan a maintenance window of a few minutes. Signed-in users stay signed in.
6
+
7
+ 1. Upgrade the site to 0.7.x first and finish the [0.7.0 checklist](#070-upgrade-checklist), including `sandcms media import-r2` until it reports no failures and `sandcms media verify`. `rebaseline` accepts only the complete 0.7 history and refuses older databases.
8
+ 2. Take a volume backup and a verified `sandcms backup` with the installed 0.7.x package.
9
+ 3. Install `sandcms@0.8.0`, review `sandcms upgrade --check`, then run `sandcms upgrade`. It updates the generated `Dockerfile` (new health check timings, `SHUTDOWN_TIMEOUT=8`, `SANDCMS_AUTO_MIGRATE=true`) and integration (graceful shutdown, no Worker settings), and adds `openship.json`. Customized integrations need the shutdown listener from `templates/integration.ts` and must stop passing `workerUrl` and `workerToken`: the `SANDCMS_WORKER_*` variables are no longer declared, so the build fails while they are read. Delete a leftover `sandcms/worker/` directory; it imports the removed `sandcms/worker` exports.
10
+ 4. Stop the site and disable automatic restarts. In a one-off container with the same volume and the new image, run:
11
+
12
+ ```sh
13
+ bun x --no-install sandcms rebaseline --database /data/sandcms.sqlite
14
+ ```
15
+
16
+ It takes the exclusive database lock (refused while a website process runs), checks the exact 0.7 history, integrity and references, writes a safety copy to `<database>.before-rebaseline-<timestamp>.sqlite`, builds the new database, copies every table, verifies that each table's rows match exactly, and only then replaces the database. On any failure the database is left untouched. Media files are not touched, and `SANDCMS_SECRET` must stay the same (two-factor secrets are encrypted with it).
17
+
18
+ 5. Start the site with the new image and check sign-in, content and media. Then apply the [platform settings](deployment.md#platform-settings) for overlapping deploys.
19
+
20
+ **Removed in 0.8.0:** the Cloudflare Worker support deprecated in 0.7.0 — `sandcms media import-r2`, the `sandcms/worker` and `sandcms/worker/local` exports, `createCMS({ workerUrl, workerToken })` and the `SANDCMS_WORKER_URL` and `SANDCMS_WORKER_TOKEN` variables. Remove the variables from the environment. `media.workerUrl` in `sandcms/config.yaml` is still accepted and ignored. See [Cloudflare](cloudflare.md).
21
+
22
+ The 0.7.x package refuses a rebaselined database. Going back means stopping the site and restoring the `before-rebaseline` copy with the 0.7.x image (`sandcms restore` of that version accepts it). Snapshots and `before-migrate` copies taken before the conversion keep the 0.7 history; 0.8.0 refuses to restore them and names `sandcms rebaseline`.
23
+
24
+ ## Compatible migrations
25
+
26
+ From 0.8.0, deploys overlap: the new release migrates while the previous one still serves, and a rollback starts the previous release on the migrated database. Every migration therefore keeps the previous release working, unless it is marked breaking:
27
+
28
+ - **Compatible (the default):** new tables, nullable columns or columns with a default, new indexes, and reviewed data changes the previous release can read. A release whose migrations are all compatible deploys by overlap and rolls back without a restore. A package started on a database with newer compatible migrations it does not know logs them and runs normally; `sandcms backup`, `restore` and the hourly snapshot accept such databases too.
29
+ - **Breaking:** a migration whose SQL contains the line `-- sandcms:breaking`, such as one that drops or renames a column the previous release uses. Its release notes say so. Deploy it stop-first: stop the site, then deploy; the new release migrates on start. An older package refuses a database after a breaking migration and names it.
30
+
31
+ Release notes list every migration and whether it is breaking.
32
+
33
+ ## 0.7.0 upgrade checklist
34
+
35
+ Version 0.7.0 moves media from Cloudflare R2 to the site's volume and includes retained migration `0009_local_media`. Run this checklist with the 0.7.x package: 0.8.0 no longer includes `sandcms media import-r2`. Follow this order when upgrading from 0.6.3; upgrading from 0.6.2 or earlier still requires the earlier checklists first. Plan a short maintenance window: images are unavailable between the deploy (step 5) and the end of the import (step 6).
36
+
37
+ 1. Check in the admin that no uploads are pending or processing, and take a backup with the installed package (`sandcms backup`, or a volume backup).
38
+ 2. Make sure the volume has free space of at least **three times** the site's current media in R2.
39
+ 3. Install `sandcms@0.7.0`, review `sandcms upgrade --check`, then run `sandcms upgrade`. Merge into customized files:
40
+ - `src/hooks.server.ts`: `cmsHandle` must be the **first** handle in `sequence()`. It enforces request size limits and serves health checks, host redirects, upload chunks and media before other hooks.
41
+ - `vite.config.ts`: remove `paths: { origin: … }` from `sveltekit()`, and add `sharp` to `ssr.external`: `external: ['bun:sqlite', 'sharp']`. See [server build configuration](deployment.md#server-build-configuration).
42
+ - A customized `src/lib/server/sandcms/index.ts`: pass `server: true`, `mediaDir: env.SANDCMS_MEDIA_DIR`, `requestLimit: env.SANDCMS_REQUEST_LIMIT`, `indexing: env.SANDCMS_INDEXING`, `canonicalRedirect: env.SANDCMS_CANONICAL_REDIRECT` and `bootstrapEmail: env.SANDCMS_BOOTSTRAP_EMAIL` to `createCMS()`, and call `media.start()` before storing the instance, closing it and rethrowing on failure, as the generated integration does. `server: true` takes the data-volume lock before the database opens. `sandcmsEnvVars()` in `src/env.ts` already declares the new variables.
43
+ - Sites with `railpack.json` keep building with Railpack: `sandcms upgrade` does not add a `Dockerfile` to them, because hosts that detect one switch builders. To switch, copy `node_modules/sandcms/templates/Dockerfile` to the project root; later upgrades then manage it.
44
+ 4. On the host, set `BODY_SIZE_LIMIT=10M`. Both overlapping and stop-then-start deploys work; see [deploys](deployment.md#deploys). Use `GET /_sandcms/health` as the health check if the host does not use the image's `HEALTHCHECK`.
45
+ 5. Deploy with `SANDCMS_WORKER_URL` and `SANDCMS_WORKER_TOKEN` still set. Migration `0009_local_media` applies on start with `SANDCMS_AUTO_MIGRATE=true`, or run `sandcms migrate`. Existing data is preserved.
46
+ 6. Run `sandcms media import-r2` in the container and check the site; see the import guide in the 0.7.x package (`docs/cloudflare.md`). Rerun it until it reports no failures.
47
+ 7. Remove the Worker variables and redeploy. Delete the Worker and its R2 bucket only once a restore from a volume backup has been verified to contain the originals; see [remove the Worker and bucket](cloudflare.md#remove-the-worker-and-bucket).
48
+
49
+ Going back to 0.6.3 after step 5 means restoring the `before-migrate` snapshot together with the old image; 0.6.3 refuses a database with migration `0009`.
50
+
51
+ ### Local media
52
+
53
+ `0009_local_media.sql` adds nullable `width`, `height` and `uploadAttempt` columns to `media` and a `leases` table for the single media processor. Existing media rows, jobs and variant sets are unchanged; the import fills `width`, `height` and variant ETags. Asset IDs, variant keys and preset versions stay the same, so published content and public image URLs keep working.
54
+
55
+ - **Uploads** are chunked through the site; the R2 signing secrets, bucket CORS and lifecycle rules are no longer used. Custom API clients must switch to the [chunked upload flow](api.md#media-uploads).
56
+ - **Processing** uses sharp in a child process. TIFF is accepted by blueprints that allow it: file blueprints without an `accept` list accept it automatically, while project-owned blueprints with an explicit `accept` list (such as the starter's `sandcms/blueprints/files/image.yaml`) need `image/tiff` added; `uploadLimit` may now be up to 500 MB, and new `media.maxPixels` (default 100 MP) and `media.maxStorage` settings limit decoded size and total storage. See [the behaviour changes](media.md#changes-from-cloudflare-processing-070).
57
+ - **New environment variables:** `SANDCMS_MEDIA_DIR`, `SANDCMS_REQUEST_LIMIT`, `SANDCMS_INDEXING`, `SANDCMS_BOOTSTRAP_EMAIL`, `SANDCMS_CANONICAL_REDIRECT`, `SANDCMS_SITE_RENAME`, `SANDCMS_ALLOW_UNMOUNTED_DATA`; see [environment](deployment.md#environment).
58
+ - **Domains:** the site now redirects hostnames other than `SANDCMS_ORIGIN`'s with a 308. Add every hostname to the proxy, then set `SANDCMS_ORIGIN` to the canonical one. If your proxy rewrites `Host`, set `HOST_HEADER` first; see [first start](deployment.md#first-start).
59
+ - **Snapshots:** the server writes `backups/latest.sqlite` next to the database every hour. Restores use it; see [backups and restore](deployment.md#backups-and-restore).
60
+ - **New commands:** `sandcms media import-r2`, `sandcms media verify [--repair]`, `sandcms media rebuild --force`.
61
+ - **Removed:** `sandcms worker update`, Cloudflare setup, the generated `sandcms/worker/*` files for new sites, and the `wrangler` requirement for site development. Existing `sandcms/worker/` files are left alone and reported as removable.
62
+ - **Deprecated, kept through 0.7.x and removed in 0.8.0:** `createCMS({ workerUrl, workerToken })`, `media.workerUrl` (ignored), the `SANDCMS_WORKER_URL` and `SANDCMS_WORKER_TOKEN` variables (read only by `media import-r2`), and the `sandcms/worker` and `sandcms/worker/local` exports.
63
+
3
64
  ## 0.6.3 upgrade checklist
4
65
 
5
66
  Version 0.6.3 adds no SQL migration and no Worker protocol change. Follow this order when upgrading from 0.6.2:
@@ -60,7 +121,7 @@ Version 0.6.0 requires SvelteKit 3 and includes retained database migrations `00
60
121
 
61
122
  1. Stop website and job processes and take a verified backup with the installed package.
62
123
  2. Install `sandcms@0.6.0` and migrate developer-owned configuration using the [SvelteKit 3 instructions](#sveltekit-3). Review `sandcms upgrade --check` and merge integration changes into customized files.
63
- 3. Deploy the protocol-5 Worker with `sandcms worker update`. Configure R2 signing credentials, bucket PUT CORS, and the one-day `incoming/` lifecycle rule for [direct uploads](cloudflare.md#direct-upload-configuration). Preserve the private `deleted/` prefix indefinitely for [durable deletion](#durable-media-deletion).
124
+ 3. Deploy the protocol-5 Worker with `sandcms worker update`. Configure R2 signing credentials, bucket PUT CORS, and the one-day `incoming/` lifecycle rule for direct uploads (see the 0.6 version of `docs/cloudflare.md`). Preserve the private `deleted/` prefix indefinitely for [durable deletion](#durable-media-deletion).
64
125
  4. Review `sandcms migrate --check`, apply integration updates with `sandcms upgrade`, then run `sandcms migrate`. Only pending migrations are applied; supported existing data is preserved.
65
126
  5. Rebuild and restart the website. Verify sign-in, editing, uploads, deletion, and form submissions on staging. Update custom API clients for paginated `{items, nextCursor}` list responses and the required document `version` on unpublish.
66
127
 
@@ -137,6 +198,8 @@ The new processing version gives rebuilt variants new keys; existing published v
137
198
 
138
199
  ## From 0.5.0: retained migrations
139
200
 
201
+ This section describes 0.5.0–0.7.x. From 0.8.0, `0000_baseline.sql` is the frozen baseline and the same rules apply to it; see the [0.8.0 checklist](#080-upgrade-checklist).
202
+
140
203
  Release 0.5.0 freezes `0000_foundation.sql` without changing its SQL or hash. Future schema changes append numbered migrations. Fresh installations apply the full history; supported databases apply only pending migrations, preserving existing data. Repeated migration is a no-op.
141
204
 
142
205
  Each migration runs in its own transaction. If one fails, that migration's SQL and history entry roll back; earlier completed migrations remain applied. Fix the cause and rerun. Modified hashes, missing history entries, and databases newer than the installed package are rejected. Use the matching package for inspection or recovery; never reset a supported database to bypass validation.
@@ -148,10 +211,12 @@ Before updating, stop website and job processes and take a verified backup using
148
211
  1. Edit `src/lib/server/db/schema.ts` and update its callers and fixtures.
149
212
  2. Run `bun run db:generate --name descriptive_change`. Drizzle generates the next SQL migration and snapshot and appends its journal entry; the script refreshes embedded `migration-data.ts` for bundler compatibility.
150
213
  3. Review SQL for data preservation, constraints, and compatibility with the transactional SQLite runner. Include any required data transformations in the new, unreleased migration. Never rewrite released migrations or snapshots.
151
- 4. Commit the schema, new migration artifacts, embedded SQL, code, tests, and documentation together.
152
- 5. Run `bun run release:check`. Cover fresh initialization, upgrades with existing data, repeated migration, rollback on failure, and incompatible history rejection.
214
+ 4. Keep the previous release working ([compatible migrations](#compatible-migrations)). The script checks every migration after the baseline and refuses drops, renames, new `NOT NULL` columns without a default, new unique indexes on existing tables, dropped unique indexes, table rebuilds (`__new_` tables), `UPDATE`/`DELETE` statements and `PRAGMA` other than `foreign_keys`. Once you have confirmed that the previous release works with such a statement, add a line `-- sandcms:compatible <reason>` to the migration; otherwise add `-- sandcms:breaking` and announce it in the release. Then rerun `bun scripts/migrations.ts`.
215
+ 5. Table rebuilds are safe to run: for SQL with `PRAGMA foreign_keys=OFF`, the runner turns foreign keys off for the whole transaction (SQLite ignores the pragma inside one), drops and recreates the triggers around it, and refuses to commit if references are left broken. Drizzle-kit does not generate triggers; write them by hand in the migration that needs them.
216
+ 6. Commit the schema, new migration artifacts, embedded SQL, code, tests, and documentation together.
217
+ 7. Run `bun run release:check`. Cover fresh initialization, upgrades with existing data, repeated migration, rollback on failure, and incompatible history rejection.
153
218
 
154
- `bun scripts/migrations.ts` only refreshes embedded SQL. Packaging includes the complete retained history. `bun run db:baseline` is disabled at 0.5.0 and later. Never use `drizzle-kit push` against deployed databases.
219
+ `bun scripts/migrations.ts` only refreshes embedded SQL. Packaging includes the complete retained history. `bun run db:baseline` is disabled; 0.8.0's `0000_baseline.sql` was regenerated once for the rebaseline. Never use `drizzle-kit push` against deployed databases.
155
220
 
156
221
  ## Moving from pre-0.5.0
157
222
 
@@ -169,7 +234,7 @@ rm -f ./data/sandcms.sqlite ./data/sandcms.sqlite-wal ./data/sandcms.sqlite-shm
169
234
  bun run dev:init
170
235
  ```
171
236
 
172
- For installed sites, initialize the fresh database with `sandcms migrate --database PATH` and then `sandcms user bootstrap --database PATH`. Update the application's database setting if you chose a new path. Recreate content and re-upload media as needed. Resetting SQLite does not delete objects in R2; old uploads are not imported into the fresh database.
237
+ For installed sites, initialize the fresh database with `sandcms migrate --database PATH` and then `sandcms user bootstrap --database PATH`. Update the application's database setting if you chose a new path. Recreate content and re-upload media as needed. Resetting SQLite does not delete files in the media directory; old uploads are not imported into the fresh database.
173
238
 
174
239
  ## Generated application files and configuration
175
240
 
@@ -180,14 +245,12 @@ bun x --no-install sandcms upgrade --check
180
245
  bun x --no-install sandcms upgrade
181
246
  bun x --no-install sandcms migrate --check
182
247
  bun x --no-install sandcms migrate
183
- # Separately, when the release requires Worker changes:
184
- bun x --no-install sandcms worker update
185
248
  ```
186
249
 
187
250
  These commands assume a compatible or fresh database. `upgrade --check` validates blueprints, checks recorded ownership and database compatibility, and prints a no-write report. `upgrade` compares generated files with hashes in `sandcms/install.json`. Unmodified generated files receive new templates. Edited files are preserved by default, with a unified diff and an explicit overwrite choice in an interactive terminal. Cancelling a prompt still produces the report without applying file changes. These ownership protections remain in place for upgrades.
188
251
 
189
- Use the protocol-5 Worker with the 0.6.0 website package; incompatible internal requests fail. See [media deployment](media.md). A media preset change requires `media rebuild`; old active variant sets remain live until each new set completes.
252
+ A media preset change requires `media rebuild`; old active variant sets remain live until each new set completes. See [media](media.md).
190
253
 
191
254
  ## Direct R2 upload upgrade
192
255
 
193
- Back up with the installed package before updating. Deploy the new Worker first; protocol 4 retains compatibility with protocol 3 website processes. Configure its R2 signing secrets, bucket PUT CORS for the admin origin and a one-day `incoming/` lifecycle rule as described in [Cloudflare configuration](cloudflare.md#direct-upload-configuration). Run `sandcms migrate` to append `0003_direct_r2_uploads.sql`, then rebuild and restart the website. The migration adds metadata-only sessions and preserves all media, jobs and pending legacy BLOB uploads. There is no reset or automatic replacement of developer-owned configuration. New browser uploads send bytes directly to R2; the website needs only its normal JSON body limit. Existing host limits can remain in place.
256
+ Back up with the installed package before updating. Deploy the new Worker first; protocol 4 retains compatibility with protocol 3 website processes. Configure its R2 signing secrets, bucket PUT CORS for the admin origin and a one-day `incoming/` lifecycle rule as described in the 0.6 version of `docs/cloudflare.md`. Run `sandcms migrate` to append `0003_direct_r2_uploads.sql`, then rebuild and restart the website. The migration adds metadata-only sessions and preserves all media, jobs and pending legacy BLOB uploads. There is no reset or automatic replacement of developer-owned configuration. New browser uploads send bytes directly to R2; the website needs only its normal JSON body limit. Existing host limits can remain in place.
package/package.json CHANGED
@@ -1,26 +1,25 @@
1
1
  {
2
2
  "name": "sandcms",
3
- "version": "0.6.3",
3
+ "version": "0.8.0",
4
4
  "scripts": {
5
5
  "dev": "bun run styles && bun --bun vite dev",
6
6
  "build": "bun run validate && bun run styles && bun --bun vite build && bun run package",
7
7
  "start": "bun build/index.js",
8
8
  "styles": "bun scripts/styles.ts",
9
- "prepare": "bun x svelte-kit sync",
9
+ "prepare": "bun --bun x svelte-kit sync",
10
10
  "package": "bun scripts/migrations.ts && bun run styles && svelte-kit sync && svelte-package && publint",
11
11
  "prepack": "bun run package",
12
12
  "check": "bun run styles && svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
13
- "test": "bun test tests",
14
- "test:e2e": "bun x playwright test",
13
+ "test": "bun test --parallel tests",
14
+ "test:e2e": "bun --bun x playwright test",
15
15
  "cli": "bun src/lib/cli/index.ts",
16
16
  "format": "prettier --write .",
17
17
  "dev:init": "bun scripts/dev-init.ts",
18
18
  "test:package": "bun run package && bun scripts/test-package.ts",
19
- "worker:dev": "bun x wrangler dev sandcms/worker/local.ts --config sandcms/worker/wrangler.jsonc --local --port 8787",
20
19
  "validate": "bun src/lib/cli/index.ts validate",
21
20
  "test:container": "bun scripts/test-container.ts",
22
21
  "preview:network": "bun scripts/preview-network.ts",
23
- "release:check": "bun run check && bun test tests && bun run test:package",
22
+ "release:check": "bun run check && bun run test && bun run test:package",
24
23
  "db:baseline": "bun scripts/migrations.ts --baseline",
25
24
  "db:generate": "bun scripts/migrations.ts --generate"
26
25
  },
@@ -56,10 +55,7 @@
56
55
  "types": "./dist/env.d.ts",
57
56
  "default": "./dist/env.js"
58
57
  },
59
- "./worker": "./dist/worker/index.js",
60
- "./worker/local": {
61
- "default": "./dist/worker/local.js"
62
- }
58
+ "./media-processor": "./dist/server/media/processor-child.js"
63
59
  },
64
60
  "peerDependencies": {
65
61
  "svelte": "^5.57.1",
@@ -67,60 +63,57 @@
67
63
  },
68
64
  "devDependencies": {
69
65
  "@fontsource-variable/geist": "5.3.0",
70
- "@playwright/test": "1.63.0",
71
- "@sveltejs/adapter-bun": "1.0.0",
72
- "@sveltejs/kit": "3.0.0",
73
- "@sveltejs/package": "3.0.0",
66
+ "@playwright/test": "1.65.1",
67
+ "@sveltejs/adapter-bun": "1.0.1",
68
+ "@sveltejs/kit": "3.2.0",
69
+ "@sveltejs/package": "3.0.2",
74
70
  "@sveltejs/vite-plugin-svelte": "7.3.1",
75
- "@tailwindcss/cli": "4.3.3",
71
+ "@tailwindcss/cli": "4.3.5",
76
72
  "@types/nodemailer": "8.0.2",
77
73
  "@types/qrcode": "^1.5.6",
78
74
  "@types/smtp-server": "3.5.13",
79
75
  "drizzle-kit": "0.31.11",
80
- "postcss": "8.5.28",
81
- "prettier": "3.9.9",
76
+ "postcss": "8.5.33",
77
+ "prettier": "3.10.1",
82
78
  "prettier-plugin-svelte": "4.1.1",
83
- "publint": "0.3.24",
84
- "shadcn-svelte": "1.7.0",
85
- "smtp-server": "3.19.13",
86
- "svelte": "5.57.1",
87
- "svelte-check": "4.7.6",
88
- "tailwindcss": "4.3.3",
79
+ "publint": "0.3.25",
80
+ "shadcn-svelte": "1.8.1",
81
+ "smtp-server": "3.21.6",
82
+ "svelte": "5.57.3",
83
+ "svelte-check": "4.7.8",
84
+ "tailwindcss": "4.3.5",
89
85
  "tw-animate-css": "1.4.0",
90
86
  "typescript": "6.0.3",
91
- "vite": "8.3.1",
92
- "wrangler": "4.140.0"
87
+ "vite": "8.3.8"
93
88
  },
94
89
  "keywords": [
95
90
  "svelte"
96
91
  ],
97
92
  "dependencies": {
98
- "@better-auth/api-key": "1.7.6",
99
- "@clack/prompts": "1.8.1",
100
- "@cloudflare/workers-types": "5.20260925.1",
93
+ "@better-auth/api-key": "1.7.25",
94
+ "@clack/prompts": "1.9.0",
101
95
  "@internationalized/date": "3.12.4",
102
- "@lucide/svelte": "1.48.0",
103
- "@tiptap/core": "3.31.3",
104
- "@tiptap/starter-kit": "3.31.3",
105
- "@types/bun": "1.4.2",
106
- "aws4fetch": "1.0.20",
107
- "better-auth": "1.7.6",
108
- "bits-ui": "2.19.3",
109
- "cn": "0.3.3",
96
+ "@lucide/svelte": "1.73.0",
97
+ "@tiptap/core": "3.34.0",
98
+ "@tiptap/starter-kit": "3.34.0",
99
+ "@types/bun": "1.4.4",
100
+ "better-auth": "1.7.25",
101
+ "bits-ui": "2.21.0",
102
+ "cn": "0.5.2",
110
103
  "diff": "9.0.0",
111
- "dotenv": "18.0.3",
112
- "drizzle-orm": "0.45.3",
113
- "jsonc-parser": "3.3.1",
114
- "lucide": "1.48.0",
115
- "nodemailer": "10.0.11",
104
+ "dotenv": "18.0.10",
105
+ "drizzle-orm": "0.45.4",
106
+ "lucide": "1.73.0",
107
+ "nodemailer": "10.6.0",
116
108
  "qrcode": "^1.5.4",
117
109
  "saxes": "6.0.0",
118
- "tailwind-variants": "3.3.1",
110
+ "sharp": "0.35.5",
111
+ "tailwind-variants": "4.0.2",
119
112
  "yaml": "2.9.1",
120
- "zod": "4.6.5"
113
+ "zod": "4.6.7"
121
114
  },
122
115
  "description": "A Bun and SvelteKit CMS with repository-owned YAML blueprints",
123
- "packageManager": "bun@1.4.0",
116
+ "packageManager": "bun@1.4.4",
124
117
  "engines": {
125
118
  "bun": "1.4.x"
126
119
  },
@@ -0,0 +1,32 @@
1
+ # Generated by SandCMS. Run one container per site with one persistent volume mounted at /data.
2
+ # Deploys overlap: the new container starts and must pass the health check (which runs pending migrations)
3
+ # before the old one is stopped. See docs/deployment.md for OpenShip, Dokploy and Coolify settings.
4
+ FROM oven/bun:1.4.4 AS build
5
+ WORKDIR /app
6
+ COPY package.json bun.lock ./
7
+ RUN bun install --frozen-lockfile
8
+ COPY . .
9
+ RUN bun run build
10
+
11
+ FROM oven/bun:1.4.4 AS deps
12
+ WORKDIR /app
13
+ COPY package.json bun.lock ./
14
+ RUN bun install --frozen-lockfile --production
15
+
16
+ FROM oven/bun:1.4.4
17
+ WORKDIR /app
18
+ ENV NODE_ENV=production \
19
+ PORT=3000 \
20
+ BODY_SIZE_LIMIT=10M \
21
+ SHUTDOWN_TIMEOUT=8 \
22
+ SANDCMS_AUTO_MIGRATE=true \
23
+ SANDCMS_DATABASE=/data/sandcms.sqlite
24
+ COPY --from=deps /app/node_modules ./node_modules
25
+ COPY --from=build /app/package.json ./
26
+ COPY --from=build /app/build ./build
27
+ COPY --from=build /app/sandcms ./sandcms
28
+ EXPOSE 3000
29
+ # Hosts switch traffic once this passes: probe often, and allow about two minutes for migrations.
30
+ HEALTHCHECK --interval=5s --timeout=5s --start-period=10s --retries=24 \
31
+ CMD ["bun", "-e", "fetch('http://127.0.0.1:' + (process.env.PORT || 3000) + '/_sandcms/health').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]
32
+ CMD ["bun", "build/index.js"]
@@ -1,21 +1,42 @@
1
1
  import { createCMS, emailOptionsFromEnv, type CMS } from 'sandcms/server';
2
2
  import * as env from '$app/env/private';
3
- let instance: CMS;
3
+ let instance: CMS | undefined, stopBackground: (() => void) | undefined;
4
+ // The adapter emits this after draining requests on SIGTERM (at most SHUTDOWN_TIMEOUT seconds). Overlapping
5
+ // deploys stop the old container this way, so stop background work, close the database and exit before the
6
+ // host's stop timeout. Leases left by unfinished work expire on their own.
7
+ process.once('sveltekit:shutdown', () => {
8
+ stopBackground?.();
9
+ instance?.close();
10
+ process.exit(0);
11
+ });
4
12
  export function getCMS() {
5
13
  if (!instance) {
6
- instance = createCMS({
14
+ // A start-up failure (e.g. another server holds the data volume) fails every request, so the
15
+ // health check stays red, instead of leaving a half-started site serving.
16
+ const cms = createCMS({
17
+ // The web server: holds the data-volume lock and runs snapshots and media processing.
18
+ server: true,
7
19
  // Enable CMS-owned SEO routes after mapping your public pages:
8
20
  // seo: { routes: { home: '/', projects: '/projects/{slug}' } },
9
21
  database: env.SANDCMS_DATABASE,
10
22
  origin: env.SANDCMS_ORIGIN,
11
23
  secret: env.SANDCMS_SECRET,
12
24
  email: emailOptionsFromEnv(env),
13
- workerToken: env.SANDCMS_WORKER_TOKEN,
14
- workerUrl: env.SANDCMS_WORKER_URL,
25
+ mediaDir: env.SANDCMS_MEDIA_DIR,
26
+ requestLimit: env.SANDCMS_REQUEST_LIMIT,
27
+ indexing: env.SANDCMS_INDEXING,
28
+ canonicalRedirect: env.SANDCMS_CANONICAL_REDIRECT,
29
+ bootstrapEmail: env.SANDCMS_BOOTSTRAP_EMAIL,
15
30
  trustedProxyHeader: env.SANDCMS_TRUSTED_PROXY_HEADER,
16
31
  autoMigrate: env.SANDCMS_AUTO_MIGRATE
17
32
  });
18
- instance.media.start();
33
+ try {
34
+ stopBackground = cms.media.start();
35
+ } catch (cause) {
36
+ cms.close();
37
+ throw cause;
38
+ }
39
+ instance = cms;
19
40
  }
20
41
  return instance;
21
42
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "volumes": ["/data"],
3
+ "readiness": {
4
+ "enabled": true,
5
+ "path": "/_sandcms/health",
6
+ "timeoutSeconds": 180,
7
+ "onFailure": "fail"
8
+ }
9
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://schema.railpack.com",
3
3
  "provider": "node",
4
- "packages": { "bun": "1.4.0", "node": "26.8.1" },
4
+ "packages": { "bun": "1.4.4", "node": "26.13.1" },
5
5
  "steps": { "build": { "commands": ["bun run build"] } },
6
6
  "deploy": { "startCommand": "bun build/index.js" }
7
7
  }
@@ -1,7 +1,7 @@
1
1
  id: image
2
2
  kind: file
3
3
  label: Image
4
- accept: [image/jpeg, image/png, image/webp, image/avif, image/gif, image/svg+xml]
4
+ accept: [image/jpeg, image/png, image/webp, image/avif, image/gif, image/tiff, image/svg+xml]
5
5
  fields:
6
6
  focus: { type: focus, label: Focal point }
7
7
  alt: { type: text, label: Alternative text }
@@ -1,6 +1,6 @@
1
1
  name: SandCMS Studio
2
+ # logo: /logo.svg # Admin sidebar logo; defaults to the site favicon. Use false for the initial.
2
3
  media:
3
- workerUrl: http://localhost:8787
4
4
  defaultFileBlueprint: image
5
5
  uploadLimit: 100000000 # At most 100 MB; originals always remain private.
6
6
  presets:
@@ -1,8 +0,0 @@
1
- export declare function resourceName(name: string): string;
2
- export declare function verifyWorkerConfig(source: string, owned: {
3
- accountId: string;
4
- worker: string;
5
- bucket: string;
6
- }): any;
7
- export declare function configureWorker(root: string, name: string): Promise<void>;
8
- export declare function updateWorker(root: string): Promise<void>;
@@ -1,135 +0,0 @@
1
- import { join } from 'node:path';
2
- import { readFileSync, existsSync, writeFileSync, chmodSync } from 'node:fs';
3
- import { parseDocument } from 'yaml';
4
- import { parse } from 'jsonc-parser';
5
- import { parse as parseEnv } from 'dotenv';
6
- import { readManifest, write } from './files.js';
7
- import { answer, confirm, run } from './prompts.js';
8
- import * as p from '@clack/prompts';
9
- export function resourceName(name) {
10
- return (name
11
- .normalize('NFKD')
12
- .toLowerCase()
13
- .replace(/[^a-z0-9-]+/g, '-')
14
- .replace(/^-+|-+$/g, '')
15
- .slice(0, 45)
16
- .replace(/-+$/, '') || 'sandcms-site');
17
- }
18
- const wrangler = ['bun', 'x', 'wrangler@4.140.0'];
19
- async function capture(args, env) {
20
- const child = Bun.spawn([...wrangler, ...args], {
21
- stdout: 'pipe',
22
- stderr: 'pipe',
23
- env: { ...process.env, ...env }
24
- });
25
- const [stdout, stderr, code] = await Promise.all([
26
- new Response(child.stdout).text(),
27
- new Response(child.stderr).text(),
28
- child.exited
29
- ]);
30
- if (code)
31
- throw new Error(stderr || stdout);
32
- return stdout;
33
- }
34
- export function verifyWorkerConfig(source, owned) {
35
- const errors = [];
36
- const config = parse(source, errors, { allowTrailingComma: true });
37
- if (errors.length ||
38
- !config ||
39
- typeof config !== 'object' ||
40
- config.name !== owned.worker ||
41
- config.account_id !== owned.accountId ||
42
- !config.r2_buckets?.some((b) => b.binding === 'MEDIA' && b.bucket_name === owned.bucket))
43
- throw new Error('Worker configuration differs from recorded project ownership. Review it before deployment.');
44
- return config;
45
- }
46
- export async function configureWorker(root, name) {
47
- const identity = JSON.parse(await capture(['whoami', '--json']));
48
- if (!identity.accounts?.length)
49
- throw new Error('Run bun x wrangler login before Cloudflare setup');
50
- const manifest = readManifest(root), prior = manifest.cloudflare;
51
- if (prior?.phase === 'ready')
52
- throw new Error('Cloudflare is already configured. Use sandcms worker update.');
53
- const accountId = prior?.accountId ??
54
- answer(await p.select({
55
- message: 'Cloudflare account',
56
- options: identity.accounts.map((a) => ({ value: a.id, label: a.name }))
57
- }));
58
- if (!identity.accounts.some((a) => a.id === accountId))
59
- throw new Error('Current Wrangler login cannot access the recorded account');
60
- const worker = prior?.worker ?? resourceName(name) + '-media', bucket = prior?.bucket ?? resourceName(name) + '-media';
61
- if (!prior) {
62
- const buckets = await capture(['r2', 'bucket', 'list'], { CLOUDFLARE_ACCOUNT_ID: accountId });
63
- if (buckets.includes(bucket))
64
- throw new Error(`R2 name ${bucket} already exists; choose a different project name`);
65
- try {
66
- await capture(['deployments', 'list', '--name', worker, '--json'], {
67
- CLOUDFLARE_ACCOUNT_ID: accountId
68
- });
69
- throw new Error(`Worker ${worker} already exists`);
70
- }
71
- catch (e) {
72
- if (!/10007|does not exist|not found/i.test(String(e)))
73
- throw e;
74
- }
75
- }
76
- if (!(await confirm(`${prior ? 'Resume' : 'Create'} Worker ${worker} and R2 bucket ${bucket} in account ${accountId}?`)))
77
- return;
78
- const file = join(root, 'sandcms/worker/wrangler.jsonc');
79
- if (prior)
80
- verifyWorkerConfig(readFileSync(file, 'utf8'), prior);
81
- else {
82
- write(file, JSON.stringify({
83
- name: worker,
84
- account_id: accountId,
85
- main: 'index.ts',
86
- compatibility_date: '2026-09-25',
87
- r2_buckets: [{ binding: 'MEDIA', bucket_name: bucket }]
88
- }, null, 2) + '\n');
89
- // Setup already installed the package Worker entry; leave any developer customization intact.
90
- await run([...wrangler, 'r2', 'bucket', 'create', bucket, '--config', file], root);
91
- manifest.cloudflare = { accountId, worker, bucket, phase: 'bucket-created' };
92
- write(join(root, 'sandcms/install.json'), JSON.stringify(manifest, null, 2) + '\n');
93
- }
94
- const envFile = join(root, '.env.local'), old = existsSync(envFile) ? readFileSync(envFile, 'utf8') : '';
95
- const secret = parseEnv(old).SANDCMS_WORKER_TOKEN || crypto.randomUUID() + crypto.randomUUID();
96
- if (!parseEnv(old).SANDCMS_WORKER_TOKEN)
97
- writeFileSync(envFile, old + `\nSANDCMS_WORKER_TOKEN=${secret}\n`, { mode: 0o600 });
98
- chmodSync(envFile, 0o600);
99
- // Establish the Worker before secret put, which otherwise prompts to create a draft Worker.
100
- // Without SANDCMS_WORKER_TOKEN, all internal endpoints fail closed. No original is public at any stage.
101
- const deployed = await capture(['deploy', '--config', file]);
102
- console.log(deployed);
103
- await run([...wrangler, 'secret', 'put', 'SANDCMS_WORKER_TOKEN', '--config', file], root, secret + '\n');
104
- await run([...wrangler, 'secret', 'put', 'SANDCMS_CF_ACCOUNT_ID', '--config', file], root, accountId + '\n');
105
- await run([...wrangler, 'secret', 'put', 'SANDCMS_R2_BUCKET_NAME', '--config', file], root, bucket + '\n');
106
- console.log(`Create an R2 API token with Object Read & Write access restricted to ${bucket}: https://dash.cloudflare.com/?to=/:account/r2/api-tokens`);
107
- const accessKey = answer(await p.password({
108
- message: 'R2 Access Key ID',
109
- validate: (v) => (v?.trim() ? undefined : 'Required for direct uploads')
110
- }));
111
- const secretKey = answer(await p.password({
112
- message: 'R2 Secret Access Key',
113
- validate: (v) => (v?.trim() ? undefined : 'Required for direct uploads')
114
- }));
115
- await run([...wrangler, 'secret', 'put', 'SANDCMS_R2_ACCESS_KEY_ID', '--config', file], root, accessKey.trim() + '\n');
116
- await run([...wrangler, 'secret', 'put', 'SANDCMS_R2_SECRET_ACCESS_KEY', '--config', file], root, secretKey.trim() + '\n');
117
- const url = deployed.match(/https:\/\/[a-z0-9.-]+\.workers\.dev/i)?.[0];
118
- if (!url)
119
- throw new Error('Worker deployed; copy its URL into config.yaml before marking provisioning ready.');
120
- const configFile = join(root, 'sandcms/config.yaml'), config = parseDocument(readFileSync(configFile, 'utf8'));
121
- config.setIn(['media', 'workerUrl'], url);
122
- write(configFile, config.toString());
123
- manifest.cloudflare = { accountId, worker, bucket, phase: 'ready' };
124
- write(join(root, 'sandcms/install.json'), JSON.stringify(manifest, null, 2) + '\n');
125
- console.log('Set SANDCMS_WORKER_TOKEN in production using ignored .env.local. Before uploading, configure R2 PUT CORS for your website origin and a one-day incoming/ lifecycle rule; see docs/cloudflare.md. R2 signing credentials are stored only as Worker secrets.');
126
- }
127
- export async function updateWorker(root) {
128
- const owned = readManifest(root).cloudflare;
129
- if (!owned || owned.phase !== 'ready')
130
- throw new Error('Cloudflare provisioning is incomplete. Rerun setup and choose Cloudflare configuration.');
131
- const config = join(root, 'sandcms/worker/wrangler.jsonc');
132
- console.log(`Worker target: ${owned.worker}; account: ${owned.accountId}; R2: ${owned.bucket}`);
133
- verifyWorkerConfig(readFileSync(config, 'utf8'), owned);
134
- await run([...wrangler, 'deploy', '--config', config], root);
135
- }
@@ -1,3 +0,0 @@
1
- DROP INDEX `access_link_recipient`;--> statement-breakpoint
2
- CREATE UNIQUE INDEX `access_invite_recipient` ON `access_links` (`kind`,`email`) WHERE "access_links"."kind" = 'invite';--> statement-breakpoint
3
- CREATE INDEX `access_link_recipient` ON `access_links` (`kind`,`email`);
@@ -1 +0,0 @@
1
- ALTER TABLE `access_links` ADD `failureReason` text;