Skip to content

WIP: feat: database backbone idea - #6274

Draft
404Wolf wants to merge 1 commit into
mainfrom
wolf/databases-fable-yolo
Draft

WIP: feat: database backbone idea#6274
404Wolf wants to merge 1 commit into
mainfrom
wolf/databases-fable-yolo

Conversation

@404Wolf

@404Wolf 404Wolf commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What this is

The first-draft skeleton of Macro Databases — user-facing tables of typed rows where SQL is the only public read/write verb. Everything compiles warning-free; every implementation is a documented todo!(). The point of this PR is to agree on the shape before filling anything in.

Full design docs live in databases-plan/ (start with sketch.md); interactive UX mock: https://claude.ai/code/artifact/635f0600-3d70-4a70-8564-f37af63042aa

The architecture in one paragraph

Postgres stores it, entity_access guards it, a per-request ephemeral in-memory SQLite runs it. Columns are bindings to models_properties property definitions (options, colors, tags, and promotion machinery reused, not copied); cells are the existing PropertyValue tagged-union JSONB, one dense object per row. User SQL executes against a permission-scoped materialization of exactly the tables it references, with the property model compiled into SQLite constraints (STRICT, CHECK from select options, FKs) so SQLite itself validates writes; the session-extension changeset is then translated into typed domain commands and applied to Postgres — the single write path.

What's in the PR

  • Migration (20260908204308_add_databases): databases, database_tables (with a version counter for liveness/caching), database_columns (placement over property_definitions), database_rows (JSONB cells), database_row_links (junction for relations).
  • crates/databases, hexagonal per the house guard (crates/reminders as template):
    • domain/models.rs — the full vocabulary: entities, schema commands, and the exec pipeline types (Catalog, TableDeps, MaterializedTable, RowChange, ExecOutcome).
    • domain/ports.rsDatabasesRepo, ColumnDefinitionStore (wraps properties), MagicTables (permission-scoped platform data: people, documents, tasks, …), SqlExecutor (analyze via authorizer → deps; sandboxed execute → results + changeset), TableEventPublisher, and the DatabasesService trait.
    • domain/service.rsDatabasesServiceImpl with the 10-step exec pipeline documented at the todo!(). The catalog build is the authorization boundary for SQL: unreadable tables don't exist at prepare time.
    • outbound/ — Postgres repo, RusqliteExecutor (rusqlite pinned to 0.32 so its libsqlite3-sys unifies with sqlx-sqlite's — cargo allows one links = sqlite3), magic-table registry, Redis event publisher. All stubs.
    • inbound/axum_router.rs — the tiny surface: POST /exec, GET /{id}/sqlite (takeout snapshot), POST / + table/column schema ops (structured because definitions carry config DDL can't express). Handlers are thin; receipted routes are todo!() pending EntityType::Database + a receipt extractor.

Deliberately NOT here yet

EntityType::Database plumbing (~26-file blast radius), the entity_access extractor, PropertyOwner::Database migration, DSS wiring, AI tools, SDK, frontend. Each is specced in databases-plan/backend-implementation.md with a phased plan.

Open questions to review

  • The SQL-only surface: schema ops stay structured (no DDL translation) — agree?
  • Concurrency: base_versions opt-in compare-and-swap, otherwise cell-level LWW.
  • GET /{id}/sqlite is read-only takeout in v1; changeset upload is a possible later tier sharing the same applier.

The first draft of the databases system: Postgres migration, a hexagonal
crates/databases with domain models/ports/service, and the SQL-first API
surface (POST /exec, GET /{id}/sqlite, structured schema ops). Every
implementation is a documented todo!(); the crate compiles warning-free
with all features.

Columns bind to models_properties definitions; cells are PropertyValue
JSONB per row; user SQL runs against per-request in-memory SQLite
materializations (rusqlite, pinned to share sqlx's libsqlite3-sys) with
session-changeset write-through. databases-plan/ holds the full design.
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Ignore keyword(s) in the title.

⛔ Ignored keywords (3)
  • WIP
  • DO NOT MERGE
  • wip

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 4e341aeb-44cf-493e-9796-94ec2f540d2e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant