Database and Migrations
Plystra v1.0 uses Ent as the canonical Go schema model and versioned SQL migrations as the production upgrade boundary.
ent/schema -> typed Core schema modelent/ -> generated codemigrations/ -> ordered production migration historyplystractl -> migration, Ent drift, and doctor checksCore Rule
Section titled “Core Rule”Production upgrades must use:
go run ./cmd/plystractl migrate upDo not use Ent auto migration as the production upgrade mechanism.
Required Checks
Section titled “Required Checks”go run ./cmd/plystractl migrate verifygo run ./cmd/plystractl ent checkgo run ./cmd/plystractl doctorThese checks verify migration state, Ent/database alignment, configuration, database connectivity, schema readiness, and service readiness.
Ent Workflow for Maintainers
Section titled “Ent Workflow for Maintainers”After editing ent/schema:
go generate ./entgo test ./...go run ./cmd/plystractl ent checkCommit schema changes, generated code, and migration files together.
v1.0 Migration History
Section titled “v1.0 Migration History”The current Core migration set includes:
| Migration | Purpose |
|---|---|
001_finance_demo | Finance Reviewer seed data and baseline authorization model. |
002_resource_registry | Resource types, actions, mappings, and registry metadata. |
003_plugin_api_preview | Plugin metadata preview tables. |
004_production_readiness | Production readiness support. |
005_official_plugins_and_templates | First-party plugin/template metadata. |
006_data_console_mutations | Data Console preview mutation support. |
007_auth_sessions | Opaque session storage. |
008_restore_database_defaults | Restored database defaults for existing schema. |
009_ent_v1_integration_guardrails | Ent integration guardrails. |
010_v1_core_required_fields | v1.0 required field alignment. |
011_ent_v1_type_alignment | Ent type alignment. |
012_ent_v1_empty_database_drift_closure | Empty database Ent drift closure. |
First-class Entity Groups
Section titled “First-class Entity Groups”| Group | Tables |
|---|---|
| Identity | users, members, user_members, sessions |
| Tenant structure | spaces, groups |
| Authorization | roles, member_roles, permissions, role_permissions |
| Resources | resources, resource_types, resource_actions, resource_mappings |
| Audit | audit_logs, audit_event_types |
| Plugin metadata | plugins, plugin_admin_menus, plugin_settings_definitions, plugin_settings_values |
| Templates and jobs | template_installations, background_jobs |
Important relationship tables such as user_members, member_roles, and role_permissions are explicit entities, not hidden join tables.
Safety Invariants
Section titled “Safety Invariants”AuditLogis append-only. Updates and deletes are blocked by Ent and store guardrails.- Soft-delete style status changes are used for many management surfaces.
MemberRolekeepsscope_anchor_group_idas a first-class field.RolePermissionhas its own ID and metadata.- User API responses do not expose
password_hash.
Upgrade Procedure
Section titled “Upgrade Procedure”- Back up PostgreSQL.
- Apply migrations.
- Verify migrations.
- Run Ent drift check.
- Run doctor.
- Restart Core.
- Smoke test operational endpoints, authz, Resource Registry, AuditLog, and request ID behavior.
Minimum commands:
go run ./cmd/plystractl migrate upgo run ./cmd/plystractl migrate verifygo run ./cmd/plystractl ent checkgo run ./cmd/plystractl doctor