{"record":{"id":"6af40bafa9156105","repo":"JuliusBrussee/caveman","slug":"postgres-inspect-tenant-tables-w","errorCode":null,"errorMessage":"postgres: inspect tenant tables: %w","messagePattern":"postgres: inspect tenant tables: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/postgresconfig/postgresconfig.go","lineNumber":238,"sourceCode":"var 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 {\n\t\treturn fmt.Errorf(\"postgres: finish tenant schema inspection: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc inspectTenantTables(ctx context.Context, queryer catalogQuerier) ([]tenantTableSchema, error) {","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/shared/platform/postgresconfig/postgresconfig.go#L220-L256","documentation":"Error \"postgres: inspect tenant tables: %w\" thrown in JuliusBrussee/caveman.","triggerScenarios":"Thrown at shared/platform/postgresconfig/postgresconfig.go:238 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the tenant table inspection 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"}