Skip to content

Develop#28

Merged
jeffersonrodrigues92 merged 6 commits into
mainfrom
develop
May 27, 2026
Merged

Develop#28
jeffersonrodrigues92 merged 6 commits into
mainfrom
develop

Conversation

@jeffersonrodrigues92

Copy link
Copy Markdown
Contributor

No description provided.

lerian-studio and others added 6 commits May 27, 2026 01:00
Expose the canonical systemplane DDL and a universal default seed from the
root systemplane package so consumers can fold schema provisioning into their
own migration pipelines instead of relying on the lib's runtime runSchema.

- Add ddl/schema.sql (byte-faithful to runtime runSchema; table
  systemplane_entries + systemplane_notify_v3() + INSERT/DELETE and UPDATE
  triggers on channel systemplane_changes; static, no placeholders).
- Add ddl/default_seed.sql (neutral runtime_config baseline,
  INSERT ... ON CONFLICT (namespace, "key") DO NOTHING).
- Embed both via //go:embed and expose SchemaSQL() / DefaultSeedSQL().
- Add unit tests; the schema test asserts the embed contains the canonical
  fragments the runtime emits (drift-prevention via consistency test).
- Update CHANGELOG.
feat(ddl): publish systemplane schema + default seed as importable artifacts
…lts seed

lib-systemplane no longer creates its schema or seeds defaults at runtime.
The Postgres store and the multi-tenant Manager previously ran CREATE TABLE
/ CREATE FUNCTION / CREATE TRIGGER plus an INSERT ... ON CONFLICT DO NOTHING
defaults seed on first use (Store.Start / OnTenantActivated). Those runtime
DDL/seed paths are removed.

Consumers now provision systemplane_entries (plus systemplane_notify_v3()
and the NOTIFY triggers) and any defaults externally using the published
SchemaSQL()/DefaultSeedSQL() (e.g. via their migration pipeline). The
runtime database role needs only DML + LISTEN — no CREATE on the schema —
which aligns with the least-privilege per-tenant roles the tenant-manager
hands back (runtime DDL otherwise fails with permission denied for
schema ... (42501)). No current consumers depend on the removed runtime
bootstrap, so this is a behavior change with no expected real-world
breakage — shipped as a non-breaking minor.

Postgres store:
- Remove runSchema and its CREATE TABLE/FUNCTION/TRIGGER builders
  (postgres_schema.go deleted).
- Remove ensureSchema / schemaOnce / schemaErr lazy-bootstrap machinery
  and the Start()/resolveDB() calls into them. Start now only opens
  LISTEN; resolveDB only resolves the tenant handle.

Manager:
- OnTenantActivated no longer runs schema creation or the runtime seed;
  it warm-loads + opens LISTEN only.
- Remove runSchemaAndSeed, runSchema, and seedDefaults.
- warmLoad tolerates a not-yet-provisioned table (SQLSTATE 42P01): it
  logs at WARN and proceeds with an empty, non-stale cache instead of
  failing activation; LISTEN/poll refreshes once the table exists.

SchemaSQL()/DefaultSeedSQL() are intact and are now the ONLY way the
schema/defaults are expressed.

Tests:
- Integration tests provision the table via the published DDL in setup
  instead of relying on runtime auto-create.
- Add a least-privilege Postgres integration test (DML-only role, no
  CREATE) proving Get/Set/Delete succeed with no runtime DDL.
- Add a Manager integration test proving activation tolerates a missing
  table, and a unit test for the 42P01 detection helper.

Recommended next version: v1.7.0 (next beta v1.7.0-beta.1). Not tagged here.
…ootstrap

feat(schema): provision schema externally; drop runtime DDL and defaults seed
@jeffersonrodrigues92
jeffersonrodrigues92 merged commit ce4a030 into main May 27, 2026
7 of 8 checks passed
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 81564f24-0d24-491d-b4a9-480bd808079d

📥 Commits

Reviewing files that changed from the base of the PR and between c8ad285 and 2c337a4.

📒 Files selected for processing (21)
  • CHANGELOG.md
  • CLAUDE.md
  • README.md
  • ddl.go
  • ddl/default_seed.sql
  • ddl/schema.sql
  • ddl_test.go
  • examples/manager/main.go
  • internal/manager/connector.go
  • internal/manager/lifecycle.go
  • internal/manager/listen_integration_test.go
  • internal/manager/manager_integration_test.go
  • internal/manager/schema.go
  • internal/manager/schema_integration_test.go
  • internal/manager/schema_test.go
  • internal/manager/testhelpers_integration_test.go
  • internal/manager/warmload.go
  • internal/manager/warmload_test.go
  • internal/postgres/postgres.go
  • internal/postgres/postgres_integration_test.go
  • internal/postgres/postgres_schema.go

Walkthrough

The PR removes schema provisioning from the library's runtime and shifts that responsibility to external consumer migrations. It exposes the DDL and seed SQL as embedded artifacts via SchemaSQL() and DefaultSeedSQL(). The Manager and Postgres Store no longer bootstrap schema; instead, warm-load now tolerates missing tables gracefully. All integration tests are updated to provision schema externally before execution.

Changes

Schema Provisioning Migration

Layer / File(s) Summary
DDL Artifacts and Public API
ddl.go, ddl/schema.sql, ddl/default_seed.sql, ddl_test.go
Embeds PostgreSQL DDL (table, trigger function, triggers) and seed SQL (default runtime_config entries) into Go strings. Exports SchemaSQL() and DefaultSeedSQL() for consumers to include in migrations. Unit tests verify artifacts are non-empty and contain canonical DDL/seed fragments.
Manager Warm-load Tolerance for Missing Tables
internal/manager/warmload.go, internal/manager/warmload_test.go
Removes seedDefaults method. Adds isUndefinedTable() helper to detect Postgres SQLSTATE 42P01. Warm-load now logs warning and proceeds with empty cache when systemplane_entries is missing, allowing activation without schema provisioning.
Manager Lifecycle and Schema Code Cleanup
internal/manager/lifecycle.go, internal/manager/schema.go, internal/manager/schema_test.go
OnTenantActivated removes runSchemaAndSeed step, proceeding directly to warmLoad then startListen. schema.go reduced to private constants and documentation. Removes seedDefaults unit tests.
Manager Test Infrastructure for External Provisioning
internal/manager/testhelpers_integration_test.go
Adds helpers: schemaDDL() reads embedded DDL file, provisionTestSchema() applies DDL to test databases, startPGForSchema() starts Postgres testcontainer, freshTenantDB() creates isolated tenant databases.
Manager Integration Tests with External Provisioning
internal/manager/manager_integration_test.go
Provisions schema externally before tests. Rewrites OnTenantActivated test to warm-load from externally seeded rows. Adds test for activation tolerating unprovisioned table. Converts all data mutations to INSERT...ON CONFLICT upserts. Removes encoding/json dependency.
Listen Integration Tests External Provisioning
internal/manager/listen_integration_test.go
Replaces m.runSchema(...) calls with provisionTestSchema(t, db) helper across six test cases.
Postgres Store Schema Bootstrap Removal
internal/postgres/postgres.go, internal/postgres/postgres_schema.go
Removes schemaOnce/schemaErr fields and ensureSchema logic from Store. Start() and resolveDB() skip schema bootstrap. Deletes postgres_schema.go entirely. Updates documentation to state external provisioning requirement.
Postgres Integration Tests with Least-Privilege Validation
internal/postgres/postgres_integration_test.go
Adds provisionSchema() helper applied before Store construction. New test validates DML-only operations succeed (no CREATE privilege required). Adds dsnWithUser() helper for credential rewriting. Updates trigger isolation test assertion.
Documentation and Examples
CHANGELOG.md, CLAUDE.md, README.md, examples/manager/main.go
Documents removal of runtime schema provisioning, new external provisioning via artifacts, least-privilege requirements (DML + LISTEN only), and warm-load tolerance for missing tables.

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

@lerian-studio

Copy link
Copy Markdown
Contributor

🔒 Security Scan Results — lib-systemplane

✅ PR Mergeable — no blocking findings

Stage Status Blocking?
Filesystem Scan ✅ Clean
Docker Image Scan ➖ Skipped
Docker Hub Health Score ➖ Skipped
Pre-release Version Check ✅ Clean

Trivy

Filesystem Scan

✅ No vulnerabilities or secrets found.


Pre-release Version Check

✅ No unstable version pins found.


🔍 View full scan logs

@lerian-studio

Copy link
Copy Markdown
Contributor

🔍 PR Validation Summary

🚫 PR Blocked — 2 blocking failures

Check Status Blocking
Source Branch ✅ success yes
PR Title ❌ failure yes
PR Description ❌ failure yes
PR Size ⏭️ skipped no
Auto Labels ⏭️ skipped no
PR Metadata ⏭️ skipped no

Fix the blocking checks above before merge.


🔍 View workflow run

@lerian-studio

Copy link
Copy Markdown
Contributor

📊 Unit Test Coverage Report: app

Metric Value
Overall Coverage 80.4% ✅ PASS
Threshold 80%

Coverage by Package

Package Coverage
github.com/LerianStudio/lib-systemplane/admin 88.4%
github.com/LerianStudio/lib-systemplane/internal/client 80.7%
github.com/LerianStudio/lib-systemplane/internal/debounce 73.1%
github.com/LerianStudio/lib-systemplane/internal/manager 87.9%
github.com/LerianStudio/lib-systemplane/internal/mongodb 97.5%
github.com/LerianStudio/lib-systemplane/internal/postgres 100.0%
github.com/LerianStudio/lib-systemplane 94.8%

Generated by Go PR Analysis workflow

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants