{"record":{"id":"385f2344330c9db4","repo":"elsa-workflows/elsa-core","slug":"storage-unit-policy-storageunit-was-not-declared-by-schema","errorCode":null,"errorMessage":"Storage unit '{policy.StorageUnit}' was not declared by schema '{schema.Name}'.","messagePattern":"Storage unit '(.+?)' was not declared by schema '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext/Physicalization/PhysicalizationPolicyValidator.cs","lineNumber":12,"sourceCode":"using Elsa.Persistence.VNext;\n\nnamespace Elsa.Persistence.VNext.Physicalization;\n\npublic static class PhysicalizationPolicyValidator\n{\n    public static PersistenceStorageUnit GetStorageUnit(PersistenceSchema schema, StoragePhysicalizationPolicy policy)\n    {\n        var storageUnit = schema.StorageUnits.SingleOrDefault(x => x.Name == policy.StorageUnit);\n\n        if (storageUnit == null)\n            throw new InvalidOperationException($\"Storage unit '{policy.StorageUnit}' was not declared by schema '{schema.Name}'.\");\n\n        var fields = storageUnit.Fields.Select(x => x.Name).ToHashSet(StringComparer.Ordinal);\n\n        foreach (var index in policy.Indexes)\n        {\n            var missingField = index.Fields.FirstOrDefault(field => !fields.Contains(field));\n\n            if (missingField != null)\n                throw new InvalidOperationException($\"Physicalized index '{index.Name}' references undeclared field '{missingField}' on storage unit '{storageUnit.Name}'.\");\n        }\n\n        return storageUnit;\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext/Physicalization/PhysicalizationPolicyValidator.cs#L1-L27","documentation":"PhysicalizationPolicyValidator.GetStorageUnit looks up policy.StorageUnit by exact name in schema.StorageUnits. If no declared storage unit matches, it throws, because a physicalization policy can only target a storage unit the schema explicitly declares.","triggerScenarios":"Calling GetStorageUnit (directly or via SqlitePhysicalizationPlanner.Plan) with a StoragePhysicalizationPolicy whose StorageUnit name does not match any storage unit name in the schema — typos, renamed units, or policies copied from another schema.","commonSituations":"Renaming a table in the schema builder without updating physicalization policies; policy defined in a separate config file drifting from code-defined schema; case sensitivity mismatches (comparison is exact).","solutions":["Set policy.StorageUnit to the exact Name of a storage unit declared in the schema.","Update the schema to declare the storage unit referenced by the policy.","Regenerate/align policy configuration with the current schema definitions after renames."],"exampleFix":"// before\npolicy.StorageUnit = \"WorkflowInstance\"; // schema declares \"WorkflowInstances\"\n// after\npolicy.StorageUnit = \"WorkflowInstances\";","handlingStrategy":"validation","validationCode":"if (!schema.StorageUnits.Any(u => u.Name == policy.StorageUnit))\n    throw new InvalidOperationException($\"Storage unit '{policy.StorageUnit}' is not declared by schema '{schema.Name}'.\");","typeGuard":null,"tryCatchPattern":"try { var unit = PhysicalizationPolicyValidator.GetStorageUnit(schema, policy); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"was not declared by schema\")) { /* fix policy or schema */ }","preventionTips":["Reference storage unit names from constants shared with the schema builder.","Regenerate policies whenever schema names change.","Keep policy config and schema in the same repo/commit."],"tags":["physicalization","schema","policy","resource-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}