Repository navigation
Description
Summary
Whether an object becomes a database table is decided by a hardcoded subtype string compare in buildExpectedSchema (migrate-ts). The consequence is that any provider-registered object.* subtype is persistable by default, with no way to opt out — so a modeling vocabulary that has nothing to do with a database silently generates DDL.
The test should be derived from persistence declarations (does the object declare a persistence source?), not from a subtype name.
Current behavior
buildExpectedSchema Pass 1 (@metaobjectsdev/[email protected], dist/expected-schema.js) excludes exactly five things:
if (child.type !== TYPE_OBJECT) continue;
if (child.isAbstract) continue;
if (child.subType === "value") continue; // ← hardcoded string compare
if (isTphSubtype(child)) continue;
const hasReadOnlySource = child.children().some(c => c instanceof MetaSource && c.isReadOnly());
const hasWritableSource = child.children().some(c => c instanceof MetaSource && c.isWritable());
if (hasReadOnlySource && !hasWritableSource) continue; // projection
// ... @unmanaged writable source → no descriptor
const tableName = resolveTableName(child);An object that declares no source.* at all falls through and gets a TableDescriptor.
Why this is a problem
1. It fails open, in the dangerous direction. The default for an unrecognized subtype is "this is a table." A new vocabulary silently acquires DDL.
2. It is unextensible, and contradicts the registry's own extensibility story. A provider can register subtypes, add attributes, add childRules, attach a validate NodeValidator — but there is no way to say "not persisted." TypeDefinition has no persistence-related field:
interface TypeDefinition {
typeId; description; factory; childRules; attributes;
dataType?; parents?; rules?; example?; whenToUse?;
maxOccurs?; defaultName?; references?; validate?;
}3. There is no config-level escape either. ResolvedGenConfig has an entities filter, so the codegen rail can be scoped to a package. ResolvedMigrateConfig and VerifyFlags have no equivalent, so the DB rail cannot. A project whose model deliberately co-loads persistable and non-persistable packages can scope one rail and not the other.
4. The available workarounds are both bad.
- Collapse the subtype into
object.value— loses the vocabulary distinction, and loses the ability to mark the subtype's own attributesrequired: true(the shared subtype must tolerate objects that lack them). Required-ness has to be re-implemented as a custom lint. - Declare a
source.rdbwith@unmanaged— a fiction.@unmanagedmeans "this table's DDL is owned by another tool"; here there is no table at all. It also keeps the object inentityToTable, so every non-persistable node contributes a fake physical table name to FK resolution — which, given that reference resolution binds on bare names, is an active collision hazard (cf. Fully-qualified @references/@from bind to a same-named entity in another package (load-order dependent; silently emits wrong FK target + invalid view DDL) #244).
Concrete impact
A real model with a wire-protocol package (155 message objects modeled as a registered object.message subtype, co-loaded with the domain entities so messages can reference the Table/Player they concern):
$ meta migrate --dry-run --dialect postgres --slug probe
UP: 157 CREATE TABLE
146 of those are wire messages — CREATE TABLE chats, CREATE TABLE pings, CREATE TABLE select_seats, CREATE TABLE table_notices. Against the live DB:
Changes: 148 create-table, 13 add-index, 1 drop-table, 13 drop-column,
6 drop-index, 6 change-column-default, 1 replace-view
meta migrate is fail-closed (it blocks every destructive change pending --allow and writes nothing), so this is not a data-loss bug — credit where due. But both migrate and verify --db are rendered unusable, and the genuine drift in that diff is buried under ~150 lines of noise.
Proposed fix
Derive persistability from a declared persistence source. An object is persistable iff it declares (or inherits) a source.*. No source ⇒ no table.
This is not a new concept — Pass 1 already reads sources to classify projections. The proposal is to promote that from a special case to the base rule.
It subsumes the existing special case exactly
FR-024 / ADR-0028 value purity already forbids a source.* child on object.value:
value object '<fqn>' must not have a source (source.<subType>) — value objects are
not persisted shapes; use subType: "entity" or "projection" for stored objects
So "no source ⇒ not persisted" excludes every value object by construction. The subType === "value" line is a redundant restatement of an invariant the general rule already covers — replacing it is behavior-preserving for values while fixing every custom subtype at once.
Backward compatibility
The risk is a model that relies on the implicit "no source but still a table" default. Worth a survey, but in our codebase every persistable object already declares its source explicitly — 44 gaming entities and 11 arena entities, zero exceptions:
- object.entity:
name: Table
children:
- source.rdb: { "@table": game_table }
- field.int: { name: id, "@column": id }If the survey finds adopters depending on the implicit default, this could land behind a config flag, or as a deprecation that first warns on "persistable object with no declared source."
Alternative / complement: make it explicit on the registration
If deriving from sources is too big a behavioral change, an explicit declaration on TypeDefinition would at least make the decision expressible:
interface TypeDefinition {
/** Whether objects of this (type, subType) can back a physical table.
* "never" — never persisted (wire messages, DTOs, view models)
* "bySource" — persistable iff a source.* is declared (proposed default) */
persistence?: "never" | "bySource";
}Deriving from sources is the better fix — it needs no new vocabulary and follows the existing "physical concerns live on the source child" principle (ADR-0007). The explicit flag is the smaller, safer step if backward compatibility blocks the general rule.
Environment
@metaobjectsdev/cli/codegen-ts0.20.8,migrate-tsbundled- dialect
postgres - One config co-loading three packages (domain entities + wire protocol + app tables); codegen rail scoped by package filter, DB rail unscopable.
Activity
fix: derive persistability from source presence, not object subtype (#…
chore(release): npm 0.20.10 · PyPI 0.19.9 · NuGet 0.19.7 · Maven 7.11.7
docs(roadmap): record the #210 ruling and its two blocking preludes
test(#271): pin sourceless projections cross-port; retire #210's fals…
feat(codegen-ts): resolveObjectNames — one resolver for every data name
fix(csharp): a sourceless concrete entity falls back to its literal t…
refactor(python): one primary-source resolver, not four with two answers
fix(codegen-python): a sourceless M:N junction/target raises, never f…
fix(csharp): a sourceless object stops claiming a table it never decl…
fix(python): the runtime asked a table name of an object that declare…
fix: review findings — a regression I introduced, and three half-true…
feat(codegen-ts): a names artifact extends its parent's instead of re…
feat(codegen): C# names classes extend their parent's instead of rest…
feat(codegen): Java and Kotlin names artifacts extend their parent's …
feat(codegen): Python names modules reference the parent's constants …
feat(cli): meta eject reports how an owned copy compares to the refer…
feat(java): a view-only projection gets a read-only Spring REST surfa…
feat(codegen): sourceless entities keep their wire contract in every …
feat(metadata): add business-rules operations and lifecycles (#610)