Cascading Key Updates on ODS / API Resources
The Ed-Fi ODS SQL Server data store allows for the configuration of Cascading Updates on entities. Cascading Update specifies that if an update is made to a key value in a data row where the key value is referenced by foreign keys, then all existing foreign key values are updated to the new key value.1
The following ODS / API resources are already configured for Cascading Updates in the as-shipped solution:
Class Period
Grade
GradebookEntry
Location
Section
Session
Student School Association
Student Section Association
However, some implementers may find it useful to enable Cascading Updates on additional resources including core resources and extension resources.
Changes are not supported in Binary installation
In order to make changes to Cascading Updates on a core resource, installation from source code is required. When changes are made, be aware that the changes could be lost when upgrading to a newer version of the API and care must be taken to reapply the changes.
Configure Cascading Updates on an Ed-Fi Core resource
Cascading key updates are configured in MetaEd by 'allow primary key updates' language construct. However since the core model cannot be updated, we provide steps to modify generated artifacts to enable cascading key updates on core resources that are not preconfigured for cascading updates.
Update the Api Model
Locate the ApiModel.json file located in <source code root directory>Ed-Fi-ODS\Application\EdFi.Ods.Standard\Artifacts\Metadata
Find the model you want to enable cascading updates on
Within the identifiers array, find the primary key identifier (isPrimary flag will be true)
Update the isUpdatable property to true
Run the code generation steps outlined in the Getting Started Guide (i.e., from a PowerShell prompt run
Initialize-PowershellForDevelopment.ps1script, followed by theinitdevcommand)Update Foreign Key Constraints for all dependencies
SQL Server - Locate the 0030-ForeignKeys.sql file located in <source code root directory>\Ed-Fi-ODS\Application\EdFi.Ods.Standard\Artifacts\MsSql\Structure\Ods
PostgreSQL- Locate the 0030-ForeignKeys.sql file located in <source code root directory>\Ed-Fi-ODS\Application\EdFi.Ods.Standard\Artifacts\PgSql\Structure\Ods
Identify all dependent resource foreign key constraints (Search for "REFERENCES [edfi].[<Resource_Name>]")
Copy each of the the ALTER TABLE scripts to a separate text document
Add a ALTER TABLE <TableName> DROP CONSTRAINT <ConstraintName> to the line before each of the copied ALTER TABLE Scripts
Add ON UPDATE CASCADE1 to each of the copied ALTER TABLE scripts
Execute all of these SQL Scripts on the target ODS
Configure Cascading Updates on an Ed-Fi Extension resource
For configuring cascading key updates on the extension resource, simply add the 'allow primary key updates' language construct to the .metaed file in your extension project. For more details on creating Ed-Fi Extensions, see here.
1 For more details on Table Cascading Updates, see here.