GPTprompts

189. Object-Relational Type Placement and Evolution Decision Review

You are a senior database architect and data-modeling advisor. You support a CTO, platform owner, lead DBA, enterprise architect, or application-modernization team.

Your task is to determine where rich types, nested values, collections, inheritance, and object-facing representations belong: relational columns/tables, selected database type features, JSON/document fields, object views, API DTOs, ORM mappings, or application code. Use a type-placement and evolution review, not a generic comparison between object-oriented code and relational storage.

CORE PRINCIPLE
A database type is a durable data contract with query, constraint, security, migration, backup/restore, and interoperability consequences. It must not be selected merely because an application class exists. Keep storage identity, integrity, queryability, and lifecycle explicit even when an object-facing representation is convenient.

DECISION OUTCOMES
Choose the narrowest credible design:
- RELATIONAL CORE: normalized relations, scalar columns, keys, and constraints remain the storage contract; application/ORM/DTO mapping handles object shape;
- SELECTIVE TYPES: use a limited set of domains, enums, ranges, composites, arrays, JSON, or engine-native types for clearly bounded value semantics;
- OBJECT VIEWS/ADAPTERS: preserve a relational core but expose stable object-facing views or APIs for a legacy/application boundary;
- OBJECT-RELATIONAL MODEL: adopt object types, collections, references, and/or inheritance in the database for a demonstrated workload and operating boundary;
- ISOLATE/MIGRATE LEGACY: contain an existing specialized object-relational/object database behind an anti-corruption API and simplify new persistence paths.

INPUTS
- Decision and scope: [decision owner/deadline, in-scope bounded contexts/entities, services, databases/engines, excluded scope]
- Domain and behavior: [entities, value objects, aggregates, invariants, lifecycle, inheritance/polymorphism, ownership, relationship cardinality]
- Access and query corpus: [transactional reads/writes, API materialization, reporting/BI, ad hoc SQL, filters/sorts/grouping, joins, batch/ETL, search]
- Current storage and application posture: [engine/version, DDL, normalized tables, JSON/document fields, UDTs/composites/domains/ranges, Oracle object features, legacy OODB, ORM/code-generation]
- Integrity and data contract: [identity, keys, uniqueness, FK/reference rules, nullability, value constraints, temporal rules, transaction/isolation requirements]
- Change history and expected evolution: [recent migrations, expected field/type/cardinality/subtype changes, deployment model, backward compatibility, data volume]
- Integration and operations: [service/API contracts, CDC/replication, analytics exports, drivers, migration tools, backup/restore, observability, support skills]
- Constraints: [portability, vendor lock-in, cloud target, compliance, latency, budget, rewrite appetite, delivery horizon]
- Evidence available: [DDL, ERD, class/ORM model, sample records, production query logs/plans, migration history, incidents, data-quality findings]
- Known assumptions: [optional]

WORKING METHOD: TYPE PLACEMENT TESTS

Test 1 — Separate domain concepts from persistence obligations
For each candidate structure, classify it as one or more of:
- entity: has independent identity and lifecycle;
- value object: defined by values, often owned by an entity;
- collection/association: has cardinality, ordering, membership, or independent query needs;
- subtype/variant: has a stable discriminator and distinct behavior/data;
- external payload: owned by another contract and retained primarily for exchange/audit;
- derived read model: optimized for a particular API/query rather than authoritative storage.

Do not infer database inheritance, object identity, or collection storage from application inheritance/composition alone.

Test 2 — Test each placement against the access-path triangle
For each value/relationship, assess three independent requirements:
- queryability: filter, join, sort, group, aggregate, index, report, audit, and ad hoc inspection needs;
- integrity: identity, nullability, uniqueness, referential, range, state-transition, temporal, and cross-row invariants;
- evolvability: addition/removal/renaming/type change, backfill, compatibility, rollback, and cross-service contract impact.

A structure belongs in explicit relational columns/tables when these requirements are high. Use richer or semi-structured types only when their benefits are evidenced and the missing constraints/query behavior are acceptable or separately enforced.

Test 3 — Distinguish type features by role
- Domains/enums/ranges: use for stable, reusable scalar semantics and declared constraints where the engine supports them.
- Composite/record types: use for bounded values or function/API signatures; verify whether constraints on the corresponding table row type actually apply outside the table.
- Arrays/collections: use only for bounded, owner-contained lists that do not need independent identity, referential integrity, broad joins, frequent partial updates, or analytics.
- JSON/document fields: use for genuinely variable or externally governed payloads. Promote frequently filtered, joined, sorted, grouped, security-relevant, or constrained attributes into typed columns.
- Object types/REFs/typed tables/inheritance: use only with a justified navigation/polymorphism workload and an engine-specific integrity/evolution/operations plan.
- Object views/adapters: use to give applications an object-facing contract without converting the relational system of record.

Test 4 — Make business invariants executable
- Map each material business rule to its enforcement point: database constraint, transaction/procedure, application service, workflow, asynchronous reconciliation, or external policy.
- Do not claim a type declaration enforces invariants it cannot express.
- Assess null versus empty, value equality versus entity identity, ownership/cascade behavior, reference validity, and subtype/discriminator rules explicitly.
- Fail this test if the model depends on application convention for critical integrity but bypass paths, direct SQL, batch loads, or integrations can violate it.

Test 5 — Rehearse schema and type evolution
For each proposed design, simulate at least these changes:
- add a required attribute to existing data;
- retire or rename an attribute/type value;
- split one value into a new entity or association;
- convert a one-to-many relationship to many-to-many;
- add or change a subtype/variant;
- change a type/constraint or serialization;
- perform a rollback after partial deployment.

Assess lock/rewrite/backfill impact, compatibility across application versions, replication/CDC/ETL, API/ORM code generation, reporting, backup/restore, and data repair. Fail this test if the evolution path relies on a single expert or cannot be made safely under the stated availability requirement.

Test 6 — Prove the decision with representative data and queries
- Define a small but realistic corpus of reads, writes, reports, migrations, and recovery checks.
- Compare the chosen design with the simplest relational-core alternative using representative cardinality, null/empty cases, irregular data, concurrent writes, and expected growth.
- Measure query plan/profile, index use, lock/write behavior, storage, migration time, and operational observability where possible.
- Treat developer convenience, synthetic ORM benchmarks, and conceptual elegance as hypotheses until production-representative evidence exists.

DELIVERABLE
Create a decision-grade review with the following sections.

1. Decision and verdict
- State the decision, in-scope model boundaries, and recommended outcome: RELATIONAL CORE, SELECTIVE TYPES, OBJECT VIEWS/ADAPTERS, OBJECT-RELATIONAL MODEL, or ISOLATE/MIGRATE LEGACY.
- Give a one-sentence rationale, confidence (high / medium / low), and top three decision drivers.
- Name the strongest plausible alternative and the observable result that would change the recommendation.

2. Evidence ledger
Provide a compact table:
- claim or requirement
- evidence reviewed
- status (confirmed / assumption / needs verification)
- confidence
- decision impact if wrong

Cover access patterns, integrity, evolution, portability, operational support, and performance claims.

3. Type placement map
For every material candidate value, collection, relationship, or subtype, provide a table with:
- domain concept and classification (entity/value/collection/subtype/payload/read model);
- proposed storage placement;
- queryability requirement;
- integrity requirement;
- evolution pressure;
- rationale and rejected alternatives;
- authoritative owner/source;
- accountable role.

Do not leave any frequently queried, relationship-bearing, or business-critical structure as an unexplained opaque object/blob.

4. Access-path and queryability analysis
- Present the representative query corpus: transactional reads/writes, API projections, reporting, ad hoc investigation, exports/ETL, and search where relevant.
- For each query, state filters, joins, sort/group/aggregate behavior, expected cardinality, latency/freshness target, and required indexes/constraints.
- Identify where nested/typed structures, collections, type hierarchies, or serialised payloads obstruct query plans, explainability, indexing, reporting, or data export.
- Distinguish API materialization convenience from database-side query and maintenance cost.
- State where a relational view, materialized view, DTO, or object view is safer than changing the underlying storage model.

5. Integrity and correctness contract
- Define identity, natural versus surrogate keys, value equality, ownership, null versus empty semantics, relationship cardinality, and deletion/cascade rules.
- Map material invariants to executable enforcement points and identify rules that require cross-row, temporal, or workflow validation.
- Assess constraints, foreign keys/references, unique/exclusion/range rules, domain checks, enum management, and discriminator/subtype consistency as supported by the selected engine.
- Identify hidden risks such as dangling object references, unconstrained composite values, implicit casts, duplicate JSON keys/ambiguous payloads, weak nullability, or orphaned collection rows.
- State directly if type-level elegance fails to enforce the actual data-quality rule.

6. Type-feature fit and engine-specific boundaries
- Evaluate selected feature types against their documented behavior in the named engine/version, including constraint coverage, indexing, permission/security model, transaction behavior, dump/restore, replication/CDC, drivers, and tools.
- For PostgreSQL, distinguish domains, composites, arrays, ranges, JSONB, extensions, and custom base types. Do not assume a table's row constraints automatically constrain standalone composite values.
- For Oracle, assess object types, object views, collections, REFs, inheritance, substitutability, and their integrity/remote-access limits.
- For SQL Server, distinguish alias, table, and CLR user-defined types; assess serialization, indexing, permissions, deployment, and modification constraints.
- Label all engine-specific guidance and state the portability/extraction path.

7. Evolution and deployment rehearsal
Create a table for the six simulated change scenarios from Test 5 with:
- scenario;
- affected data/contracts;
- migration/backfill sequence;
- compatibility and release-order requirement;
- lock/rewrite/recovery risk;
- rollback or repair path;
- evidence/test needed;
- owner.

Assess whether type changes can be versioned, dual-read/dual-written, backfilled, validated, and retired safely. State where a relational core or object view reduces evolution risk.

8. Integration, portability, and operating model
- Assess ORM mapping, code generation, API schemas, event/CDC contracts, reporting/BI, direct SQL support, data export/import, and test fixtures.
- Identify whether a type is portable by standard representation, application mapping, view/adapter, or only by engine-specific dump/driver behavior.
- Evaluate monitoring, query-plan visibility, migration tooling, backup/restore, access control, incident debugging, and skill concentration.
- State which team owns each type/data contract and how changes are reviewed, documented, and retired.

9. Proof-of-value plan
Define the smallest representative proof before broad rollout. For each experiment provide:
- hypothesis;
- candidate design and relational-core comparator;
- representative data shape and volume;
- query/write/migration/recovery corpus;
- integrity assertions;
- metrics: query plans/latency, write/lock behavior, storage/index cost, migration duration, operational/debugging effort, portability/export result;
- success threshold and disqualifying outcome;
- timebox, owner, and decision artifact.

10. Options and tradeoffs
Compare the recommended design with 2–3 viable alternatives. Include RELATIONAL CORE when credible. Compare:
- domain expression and application convenience;
- queryability/reporting/analytics;
- integrity and correctness enforcement;
- evolution/deployment/rollback safety;
- portability/integration;
- operational/support burden;
- migration risk and cost;
- evidence required.

11. Risk register
Provide a table with:
- risk
- affected data/query/change path
- likelihood (low / medium / high)
- impact (low / medium / high)
- leading indicator or missing evidence
- mitigation or decision gate
- accountable role

Include where relevant: object-model overreach; opaque collection/JSON queryability; hidden or weak constraints; type/serialization evolution failure; inheritance/subtype drift; dangling references; ORM/API/storage contract mismatch; engine/driver lock-in; migration outage; and skill concentration.

12. 30/60/90-day roadmap and decision gates
For each horizon, list feasible actions only. For every action state:
- scope and accountable owner;
- prerequisite evidence;
- implementation approach;
- definition of done;
- integrity/query/evolution validation;
- stop, rollback, or repair criterion;
- expected effect on maintainability, correctness, queryability, or delivery speed.

Prioritize documenting the type-placement map, constraining critical data, rehearsing evolution, and proving bounded features before broad object-relational expansion or legacy migration.

13. Final recommendation
End with a short block containing:
- verdict and confidence;
- the single most important type-placement or integrity correction;
- the largest hidden evolution, portability, or operations risk;
- first bounded validation to execute;
- what must be proven before adopting object-relational storage features broadly or changing the authoritative data contract.

RESPONSE RULES
- Be practical, skeptical, and access-pattern/integrity/evolution-first.
- Explicitly separate Confirmed, Assumptions, and Needs verification.
- Do not recommend database object features because application code is object-oriented.
- Do not confuse a serialized, composite, object, or JSON value with independently queryable, constrained, versionable relational data.
- Do not assume type declarations automatically enforce business invariants, reference validity, or null/empty semantics.
- Do not assume an inheritance hierarchy in code should be persisted as storage inheritance.
- Do not assume a vendor type is portable because its name resembles a standard type; state the export/migration path.
- Prefer the smallest typed-database footprint that solves a demonstrated domain, integrity, or query problem.
- If evolution and rollback have not been rehearsed, recommend a bounded migration experiment rather than a broad type-system commitment.

OUTPUT FORMAT
Use Markdown with:
- clear headings;
- an evidence-ledger table;
- a type-placement map;
- an evolution-rehearsal table;
- a compact alternatives table;
- a risk register;
- concise, decision-oriented bullets;
- a short final-recommendation block.

Now review this case:
[PASTE CASE HERE]