Skip to content

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 model
ent/ -> generated code
migrations/ -> ordered production migration history
plystractl -> migration, Ent drift, and doctor checks

Production upgrades must use:

Terminal window
go run ./cmd/plystractl migrate up

Do not use Ent auto migration as the production upgrade mechanism.

Terminal window
go run ./cmd/plystractl migrate verify
go run ./cmd/plystractl ent check
go run ./cmd/plystractl doctor

These checks verify migration state, Ent/database alignment, configuration, database connectivity, schema readiness, and service readiness.

After editing ent/schema:

Terminal window
go generate ./ent
go test ./...
go run ./cmd/plystractl ent check

Commit schema changes, generated code, and migration files together.

The current Core migration set includes:

MigrationPurpose
001_finance_demoFinance Reviewer seed data and baseline authorization model.
002_resource_registryResource types, actions, mappings, and registry metadata.
003_plugin_api_previewPlugin metadata preview tables.
004_production_readinessProduction readiness support.
005_official_plugins_and_templatesFirst-party plugin/template metadata.
006_data_console_mutationsData Console preview mutation support.
007_auth_sessionsOpaque session storage.
008_restore_database_defaultsRestored database defaults for existing schema.
009_ent_v1_integration_guardrailsEnt integration guardrails.
010_v1_core_required_fieldsv1.0 required field alignment.
011_ent_v1_type_alignmentEnt type alignment.
012_ent_v1_empty_database_drift_closureEmpty database Ent drift closure.
GroupTables
Identityusers, members, user_members, sessions
Tenant structurespaces, groups
Authorizationroles, member_roles, permissions, role_permissions
Resourcesresources, resource_types, resource_actions, resource_mappings
Auditaudit_logs, audit_event_types
Plugin metadataplugins, plugin_admin_menus, plugin_settings_definitions, plugin_settings_values
Templates and jobstemplate_installations, background_jobs

Important relationship tables such as user_members, member_roles, and role_permissions are explicit entities, not hidden join tables.

  • AuditLog is append-only. Updates and deletes are blocked by Ent and store guardrails.
  • Soft-delete style status changes are used for many management surfaces.
  • MemberRole keeps scope_anchor_group_id as a first-class field.
  • RolePermission has its own ID and metadata.
  • User API responses do not expose password_hash.
  1. Back up PostgreSQL.
  2. Apply migrations.
  3. Verify migrations.
  4. Run Ent drift check.
  5. Run doctor.
  6. Restart Core.
  7. Smoke test operational endpoints, authz, Resource Registry, AuditLog, and request ID behavior.

Minimum commands:

Terminal window
go run ./cmd/plystractl migrate up
go run ./cmd/plystractl migrate verify
go run ./cmd/plystractl ent check
go run ./cmd/plystractl doctor