Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
Upgrades And Customization — The Solutions Document
This is the doctrine for the hardest problem in packaged app systems: how a third-party package upgrades in place while the operator's data AND customizations survive. Rails and Django never solved this as a platform property — apps/engines existed, but customizing meant forking and upgrading meant being your own integrator. The systems that solved it (Salesforce managed packages, Odoo modules, Debian conffiles, WordPress child themes) converged on the same handful of ideas. This document adapts them to DBBASIC so any future contributor — human or AI — builds with the upgrade system instead of fighting it.
Status: Read This First
This page is the design doctrine. What installs do today is written down in package-authoring.md ("What Install Actually Does Today", "What A Schema's version Does", "Upgrading A Package"); where the two differ, that page is right. Checked against the code on 2026-11-30:
| Idea below | Today |
|---|---|
| Rule 0 baselines | built: data/package_baselines/<id>.json, used for schemas, seed rows and permission rules |
| Rule 1 reconcile | built for objects (pristine updated, customised kept, a real conflict parked as a reconcile record by object_reconciles), schemas (merged field by field) and permission rules (retracted when pristine) |
| Rule 2 overlays | built: an existing object is rewritten where it lives, a new one goes to the base root; override roots shadow by id |
| Rule 3 extra data | built: a field with "store": "extra"; migrations are not built |
| Rule 4 hooks | HANDLES event handlers exist (event-hooks-decisions.md); page slots are not re-checked here |
| Rule 5 flags | a feature_flags schema ships in app-settings; the shared helper and user_prefs are not re-checked here |
There is no data backfill on upgrade. Records are never rewritten by an install; a field added later reads empty on old rows, and a default fills new writes only. migrations in a manifest are refused until run semantics exist. Until they do: keep changes additive, make readers cope with empty, and backfill as a separate, repeatable step you run yourself. The pattern and an upgrade test you can run are in Upgrading A Package.
The Three Layers (never entangle them)
Every installed app is three independent layers:
- Package baseline — what the package shipped: objects, schemas,
permission fragments, seed. Versioned, replaceable, owned by the package.
- Local customization — what this instance changed on top: edited
source, added fields, extra rules, user code. Owned by the operator.
- Data — the records in
data/collections/<name>/records.tsv. Owned by
the users. Lives entirely outside the package (already true today).
An upgrade replaces layer 1. It must never silently destroy layers 2 or 3. Layer 3 is solved: seed rows merge by id and never overwrite a live row an operator changed (see package-authoring.md). A seeded row's columns follow the same baseline rule as schemas: a column the package changed is refreshed only when it still holds what the last install wrote, and an edited one is kept and reported (Changing a seeded row in a new version). This document is about layer 2.
Rule 0: Provenance Baselines
Nothing else works without this. On install/upgrade, stamp every shipped artifact with its baseline:
{"package": "app-articles", "version": "0.2.0", "sha256": "<hash of shipped source>"}
stored per object and per schema (e.g. data/package_baselines/<pkg>.json). Then "is this customized?" is a computable question: hash the live source and compare to the baseline. Without the stamp you cannot distinguish a human's edit from the shipped file, and every upgrade is a coin flip.
Rule 1: Reconcile, Don't Replace
On upgrade, per object/schema, three-way compare old_baseline vs live vs new_shipped (exactly git merge / dpkg conffile semantics):
| live vs baseline | shipped changed? | action |
|---|---|---|
| pristine | — | fast-forward to new version, update baseline (silent) |
| customized | no | keep the customization (silent) |
| customized | yes, hunks don't overlap | three-way merge, apply, flag "merged" |
| customized | yes, conflict | park it — write a pending-reconcile record holding both versions, leave live untouched, surface for a human decision (keep mine / take theirs / view diff) |
allow_replace means "fast-forward the pristine ones." Discarding a customization requires a separate explicit force. The existing version stores (object_versions, object_schema_versions) are the undo; the install restore point is the rollback (when reinstalling many packages, name one shared backup with "restore_point" rather than writing an archive each; see single-vm-deployment.md). A "reconcile inbox" (Scroll screen + CLI list) holds parked conflicts — upgrades never block on them.
Permission rules follow the same comparison with one difference in shape: the unit is a rule, not a file, and the policy file is shared with the operator. The baseline records the rules a package shipped; an upgrade removes a rule that is in the baseline, is no longer shipped, and is still in the policy exactly as shipped and tagged as the package's (pristine → fast-forward). A rule the operator edited or wrote is never removed; it is kept and reported, never parked, because there is nothing to merge — the operator's rule simply stays in force. Boxes installed before rules were baselined rely on the package's explicit retracted list. See "Package Rules And Upgrades" in permissions-model.md.
One rule an upgrade can never remove: the old starter grant. The starter policy used to ship {"effect": "allow", "principal": "registered", "actions": ["read", "execute"]} with no collection and no object ("signed-in users can read and run objects"). It is the operator's (no package tag), so retraction leaves it, and it quietly overrides everything a package grants: every signed-in user can run every object and read every collection. New boxes no longer start with it. On a box that does, GET /permissions/unshipped flags it as wide (and wide_rules lists it), and the startup log names it. Remove it deliberately after an upgrade: GET /permissions/policy, drop the rule, PUT /permissions/policy with the rest unchanged (the exact commands are in "A wide rule left over from an older starter policy" in permissions-model.md). Packages ship the grants their own pages need, so most boxes lose nothing; audit mode shows the rest.
Rule 2: Customize By Overlay, Not By Editing Core
The reconcile engine is the safety net. The preferred path makes conflicts structurally impossible: customizations live in different files than the package's, so upgrades and edits never touch the same bytes.
- System vs user objects. Package-shipped objects are system objects
(baseline-stamped, upgrade-managed). Operator-created objects are user objects (never touched by any upgrade). The namespace should make this visible: editing a system object warns "this came from app-articles 0.2.0 — override instead?"
- Override objects. A user object can shadow a system object by id:
the resolver checks the override root first (objects/overrides/… or an overrides: {site_articles: my_articles} map). The shipped object stays pristine and freely upgradeable; the override persists across upgrades. This is Odoo _inherit / WordPress child themes done with plain files.
- Where an install writes. A NEW package object is written to the
base/system root, never the override root — object_namespace. get_base_object_roots is explicit that this is "the root packages install into and reconcile against ... the pristine, upgradeable copy". An object that ALREADY exists is rewritten wherever it already lives, so an operator's override survives every upgrade. Both halves matter: installing into the override root would make package content indistinguishable from customization, and it also silently disables event handlers (see event-hooks-decisions.md Decision 2 — an override is invisible to the handler index).
- Extension points. Objects should invite extension instead of forking:
named hooks (see Rule 4) and small overridable pieces rather than one monolith page.
Rule 3: Data Fields That Survive Schema Upgrades
Schemas are the friendly layer because changes are mostly additive, and records are read through the schema — an old row simply reads empty for a new field (proven by the created_at rollout).
- Field union on upgrade. Merge shipped schema changes with locally added
fields rather than replacing the field list. Conflict = same field name with a different type/enum — park it like a source conflict. A locally added priority field must survive an app-notes upgrade.
- Namespace local fields (
x_prefix by convention, enforced gently) so
a package can never ship a field that collides with an operator's.
- Extension data (
extra). Give every collection an optional JSON
overflow field — the json_p idea: user-defined per-record data that no schema upgrade can ever collide with, because it isn't in the schema's flat namespace at all. Schemas may declare typed views into it ({"name": "x_mood", "store": "extra"}) so forms/lists render extension fields with zero migration. TSV stays one column; the column holds JSON.
- Migrations (the currently-stubbed manifest section) are for the rare
non-additive change: a shipped script that backfills/transforms records, run once, marker-tracked, restore-point-first. Not built (install refuses a package that lists one). Until it is, packages keep schema changes additive and backfill by hand; see Status above.
Rule 4: Hooks — Behavior Customization Without Forking
Let operators attach code to the system's existing event stream instead of editing package objects. The substrate exists: every record write already publishes collection.record.created/updated/deleted (it drives /ws).
- Event handler objects. A user object subscribes declaratively:
HANDLES = ["notes.record.created"]; the server invokes it on the event (same sandboxed execution as any object). Custom side effects — notify, enrich, sync — with zero edits to the shipped app. Handlers are user objects, so upgrades never touch them.
- Page hooks. Generated pages expose named slots (
before_list,
row_actions) that resolve to user objects if present. The generative renderer makes this cheap: one hook added to site_list appears in every app at once.
Rule 5: User Prefs And Feature Flags
A user_prefs collection (user_id, key, value, owner-scoped rows) — schema-driven like everything else — gives:
- Per-user settings for any app (theme, defaults, layout) with zero new
endpoints; the generators can read/write it directly.
- Feature flags. Packages ship features dark:
features.json → {"kanban_view": {"default": "off"}}. Instance-level toggles live in a feature_flags collection; per-user overrides in user_prefs. Pages check flags via one shared helper. This decouples shipping code from enabling it — upgrades can carry big features safely off, canary them per user, and roll back by flipping a flag rather than reinstalling. It also shrinks customization pressure: many "edits" are really "turn this on/off," which should be config, not forked source.
What Future Coders (AI Or Human) Must Do
When touching packages or upgrade code:
- Never write an upgrade path that overwrites a file without checking its
baseline hash first. If the baseline system doesn't exist yet, build it before the feature that needs it.
- Never block an install on something preservable — preserve and skip
(like seed), or park and surface (like conflicts). Blocking teaches operators to bypass the installer, which is how systems rot.
- Keep schema changes additive; put anything non-additive in a migration.
- New customization mechanisms must be overlay-shaped: separate file,
separate collection, separate namespace — never "edit the shipped thing."
- Data outside the package, keyed by collection, always.
Build Order (the original plan; see Status for what is done)
- Provenance stamps — done.
- Reconcile-on-upgrade — done for objects, schemas and permission rules.
- Override objects — done.
- Schema field-union +
extraextension data — done; migrations not. - Event handler objects (
HANDLES) — done; page hooks open. - user_prefs + feature_flags — partly (see Status).
Each phase was independently shippable and independently valuable; together they make "upgrade the app, keep your data and your customizations" a platform guarantee — the property that separated the systems that lasted (Salesforce, Odoo, Debian, WordPress) from the frameworks that made every operator their own integrator.