Schema Alignment Guide
Step-by-step guide for completing the database schema alignment introduced in Engage 17.2.0, including the rewritten analytics data cleanup system.
Engage 17.2.0 introduces a rewritten analytics data cleanup system and a database schema alignment. This guide walks you through the required post-upgrade steps.
Analytics data cleanup changes
The analytics data cleanup has been fully rewritten. It now processes all eligible records in a single pass rather than working in fixed-size batches.
New configuration settings
The cleanup schedule is configured under Engage:Analytics:DataCleanup in your appsettings.json:
{
"Engage": {
"Analytics": {
"DataCleanup": {
"Enabled": true,
"FirstRunTime": null,
"StartupDelay": "00:05:00",
"Interval": "1.00:00:00",
"CommandTimeout": 1200
}
}
}
}Enabled
Whether the data cleanup process runs at all.
true
FirstRunTime
Optional crontab expression to schedule the first cleanup run. When set, the calculated delay must still be at least StartupDelay.
null
StartupDelay
Minimum time after application startup before the first cleanup run. Used directly as the delay when FirstRunTime is not set.
00:05:00 (5 minutes)
Interval
Interval between cleanup runs.
1.00:00:00 (24 hours)
CommandTimeout
Database command timeout in seconds.
1200 (20 minutes)
How the cleanup pipeline works
The cleanup runs as a background job on a recurring schedule. Each run executes three phases in order:
Anonymize — Replaces personally identifiable information with anonymized values for data that has exceeded the
AnonymizeAnalyticsDataAfterDaysretention period.Delete analytics data — Deletes pageviews, control group data, and raw data that has exceeded its respective retention period (
DeleteAnalyticsDataAfterDays,DeleteControlGroupDataAfterDays,DeleteRawDataAfterDays).Delete orphaned data — Removes records no longer referenced by any analytics data, such as sessions, visitors, and devices without pageviews.
You can extend the cleanup pipeline with custom data cleanup processors.
Database schema alignment
The schema alignment brings existing installations in line with a clean install by adding missing foreign keys (with ON DELETE CASCADE), indexes, and constraints. This is a manual post-upgrade step that requires running SQL scripts during a maintenance window.
Why this is needed
Older installations may have accumulated orphaned records over time. The new foreign key constraints with ON DELETE CASCADE require that all existing data satisfy these relationships. Running the scripts ensures your database is consistent before the constraints are added.
Post-upgrade steps
After upgrading to 17.2.0, follow these steps during a maintenance window:
Determine a safe DeleteAnalyticsDataAfterDays value
Run the GetDeleteAnalyticsDataAfterDays.sql script against your database. This analyzes your data volume and recommends a safe initial value for the DeleteAnalyticsDataAfterDays setting.
Update your appsettings.json with the recommended value before proceeding. This ensures the first cleanup run does not attempt to delete an excessive number of records at once.
Ensure data consistency
Run the EnsureDataConsistency.sql script against your database. This script cleans up orphaned records across all Engage tables. It removes or nullifies rows that reference non-existent parent records, and then re-validates all existing foreign key constraints.
This step is required before running the schema alignment script. Without it, the CompleteAlignSchema.sql script will fail if orphaned data violates the new constraints.
Complete the schema alignment
Run the CompleteAlignSchema.sql script against your database. This re-creates all foreign keys with ON DELETE CASCADE and re-enables any disabled or untrusted constraints. It also adds any missing indexes to align your schema with a clean install.
The script is safe to re-run if a batch fails. The first failing batch surfaces the root-cause error and subsequent batches no-op cleanly — fix the cause, then re-run the script.
Engage data in a separate database
If your Engage analytics data lives in a different database from your Umbraco core tables, set the script's separateDatabaseMode flag before running it. Near the top of CompleteAlignSchema.sql you will find:
Change the 0 to 1, then run the script against your Engage database.
In separate-database mode the script:
Skips all
umbracoKeyValuereads and writes.Verifies (instead) that the Engage tables exist in the database it is connected to.
Prints, at the end, the SQL
UPDATEstatement you need to run manually against your Umbraco database to mark the migration asComplete.
Until you run the printed UPDATE statement against your Umbraco database, the Engage health check will continue to show the Aligned warning.
Monitoring
Two new Engage health checks are available in the Umbraco Health Check dashboard:
Database Schema Status — Verifies the
Umbraco.Engage+DatabaseSchemaStatuskey is set toComplete.Constraint Integrity — Validates that all expected foreign keys and indexes are present.
Downloading the scripts
DeleteAnalyticsDataAfterDays value based on your data.CompleteAlignSchema.sql to clean up orphaned data and verify all foreign key constraints.EnsureDataConsistency.sql to add missing foreign keys, indexes, and constraints.Last updated
Was this helpful?