{"record":{"id":"c9518afe4dfb5b7a","repo":"JuliusBrussee/caveman","slug":"postgres-begin-tenant-schema-inspection-w","errorCode":null,"errorMessage":"postgres: begin tenant schema inspection: %w","messagePattern":"postgres: begin tenant schema inspection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/postgresconfig/postgresconfig.go","lineNumber":232,"sourceCode":"\n// organizationPolicyExpression matches the only accepted tenant predicate:\n// organization_id equals the transaction-local tenant GUC, optionally cast to\n// the column's scalar type by PostgreSQL. It is anchored so OR TRUE, a different\n// operator, a different GUC, or an extra predicate cannot pass by containing\n// the two expected strings.\nvar organizationPolicyExpression = regexp.MustCompile(`^organization_id=\\(*current_setting\\('app\\.current_organization_id'(?:::text)?(?:,true)?\\)\\)*(?:::[A-Za-z_][A-Za-z0-9_.$\"]*)?$`)\n\n// ValidateTenantSchema proves structural isolation invariants that are easy to\n// regress during schema evolution. Every tenant table must fail closed under\n// FORCE RLS, and every foreign-key edge between tenant tables must carry the\n// shared organization scope (plus project scope when both tables have it).\nfunc ValidateTenantSchema(ctx context.Context, pool *pgxpool.Pool) error {\n\ttx, err := pool.BeginTx(ctx, pgx.TxOptions{\n\t\tIsoLevel:   pgx.RepeatableRead,\n\t\tAccessMode: pgx.ReadOnly,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"postgres: begin tenant schema inspection: %w\", err)\n\t}\n\tdefer tx.Rollback(ctx)\n\n\ttables, err := inspectTenantTables(ctx, tx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"postgres: inspect tenant tables: %w\", err)\n\t}\n\tforeignKeys, err := inspectTenantForeignKeys(ctx, tx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"postgres: inspect tenant foreign keys: %w\", err)\n\t}\n\tif violations := tenantSchemaViolations(tables, foreignKeys); len(violations) > 0 {\n\t\treturn fmt.Errorf(\"postgres: tenant schema isolation incomplete: %s\", strings.Join(violations, \"; \"))\n\t}\n\tif err := validateResolverSchema(ctx, tx); err != nil {\n\t\treturn err\n\t}\n\tif err := tx.Commit(ctx); err != nil {","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/shared/platform/postgresconfig/postgresconfig.go#L214-L250","documentation":"Error \"postgres: begin tenant schema inspection: %w\" thrown in JuliusBrussee/caveman.","triggerScenarios":"Thrown at shared/platform/postgresconfig/postgresconfig.go:232 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the tenant schema inspection transaction error and retry."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}