How to Test Data Migration Scripts Before Production
Data migration scripts rarely fail because a single SQL statement is obviously wrong. Problems usually arise from assumptions about formats, missing values, duplicate records, relationships, permissions, or the way a legacy system represents business rules. A migration can appear successful while quietly dropping history, changing account balances, or creating records that users cannot reconcile. Learn more about About.
A disciplined pre-production approach treats migration as a software delivery activity rather than a one-off database exercise. Teams should test the scripts, the data, the target environment, the operational runbook, and the rollback plan together. This is especially important in Australia, where systems may handle Medicare details, superannuation records, customer identity information, and data distributed across widely separated offices. Learn more about Contact.
Define The Migration Contract
Start by writing down what the migration is expected to do. This contract should identify the source and target systems, entities in scope, transformation rules, exclusions, dependencies, and ownership of each data set. It should also state whether the migration is a one-time cutover, a staged transfer, or a repeatable process for ongoing synchronisation.
Define measurable acceptance criteria before testing begins. For example, every active customer must appear in the target, balances must reconcile to the cent, inactive records must retain their status, and migrated dates must preserve the correct timezone and meaning. A statement such as “the data looks right” is too vague to support a production decision.
Business representatives should approve the rules, not just technical staff. A finance specialist may know that a blank value means “not applicable”, while an engineer may interpret it as missing data. In a Melbourne payroll migration, for instance, an employee’s employment status, tax details, leave balances, and superannuation fund information may need separate validation.
Profile Source And Target Data
Profile the source before writing extensive test cases. Measure row counts, null rates, duplicate keys, invalid codes, unusual character sets, date ranges, orphaned relationships, and unexpectedly large fields. Profiling often reveals that the migration script is being asked to solve a data quality problem that should be addressed separately.
Run the same profiling checks against the target after each test migration. Compare totals by useful business dimensions, such as customer type, state, product, account status, or transaction month. Aggregate comparisons can identify a problem quickly, while record-level checks explain which records are affected.
Use production-like data without exposing personal information unnecessarily. Mask names, addresses, email addresses, payment details, and government identifiers while retaining the patterns needed for testing. Australian organisations should align this approach with the Privacy Act and their internal data handling policies, including any requirements concerning offshore test environments.
Test Mappings And Transformations
Build a mapping specification that shows the source field, target field, conversion rule, default value, validation rule, and treatment of rejected records. This document becomes the reference point for test design and makes undocumented assumptions visible. It should cover data types, precision, text length, character encoding, date formats, and code translations.
Create positive, negative, boundary, and representative test records. Include blank strings, nulls, leading zeroes, maximum-length text, invalid postal codes, duplicate identifiers, future dates, historical dates, negative amounts, and records with non-ASCII characters. Australian addresses should include state abbreviations, apartment details, rural delivery formats, and postcodes from locations such as Darwin, Perth, and regional New South Wales.
Test transformations independently where possible. A script that converts a legacy status of A into “Active” should be tested separately from the process that loads the customer record. This makes failures easier to isolate and helps automation produce precise evidence rather than a single pass-or-fail result.
Reconcile Records And Business Totals
A successful database load does not prove that the migration is correct. Reconciliation should compare source and target counts, key fields, relationships, financial totals, status distributions, and selected record samples. Where records are intentionally excluded, produce an auditable exclusion report with the reason and owner for each category.
Use control totals for high-value or regulated data. Compare invoice totals, outstanding balances, order quantities, payroll amounts, loyalty points, or claim values before and after the transformation. Test both overall totals and smaller groupings, since an error affecting one product or branch may disappear inside a large aggregate.
| Validation Area | Useful Check | Evidence To Retain |
|---|---|---|
| Completeness | Source and target counts by entity and status | Query output and variance report |
| Accuracy | Field-level comparison on sampled records | Automated diff results |
| Relationships | Foreign keys, parent-child links, and orphan counts | Constraint report |
| Financial integrity | Sums, balances, taxes, and transaction counts | Signed reconciliation |
| Exceptions | Rejected, skipped, or transformed records | Error and exclusion logs |
| Repeatability | Results from running the process again | Run identifiers and checksums |
Have business users review a risk-based sample rather than asking them to inspect everything. Include ordinary records and difficult cases, such as a long-standing customer with several addresses, a partially refunded order, or a policy with multiple historical versions. Their approval should be recorded against clear criteria.
Exercise Failure And Rollback
Migration testing must include failure injection. Stop the process during extraction, transformation, loading, index creation, and post-load validation. Check whether the script leaves partial records, commits transactions too broadly, or can safely resume from a known checkpoint.
Test duplicate execution as well. A reliable migration should be idempotent where practical, meaning that rerunning it does not create duplicate customers or transactions. If the process cannot be rerun safely, document exactly how operators identify the failed batch and clean up or restore the affected data.
Prepare a rollback strategy that is technically executable within the available outage window. Restoring a full database backup may be too slow for a business that operates across Sydney, Brisbane, and Perth. Consider reversible feature flags, isolated target schemas, snapshots, point-in-time recovery, or a controlled fallback to the legacy system, then rehearse the chosen method.
Measure Performance And Operational Risk
Run performance tests with realistic volumes and concurrency. A script that handles 50,000 test records may struggle with 20 million production rows, particularly when indexes, triggers, audit tables, or encryption are enabled. Measure throughput, memory, CPU, locking, network traffic, database growth, and the time required for verification.
Test the migration in an environment that resembles production architecture. Include the same database engine version, integration endpoints, authentication model, storage configuration, and scheduled jobs. A slow connection between a cloud region and an Australian data centre can change the result significantly, as can a cutover scheduled during the AEST or AEDT business day.
Account for operational constraints such as EOFY processing, payroll cycles, public holidays, and retail peaks. A migration timed around 30 June may compete with financial reporting and tax-related workloads. Regional organisations may also have limited technical coverage outside normal hours, so monitoring, escalation contacts, and handover instructions need to be explicit.
Secure Scripts Logs And Test Data
Review migration scripts as production code. Check for hard-coded credentials, excessive privileges, unsafe dynamic SQL, unencrypted temporary files, and sensitive values written to logs. Use managed secrets, least-privilege service accounts, parameterised queries, and controlled access to scripts and evidence.
Security testing should cover the entire migration path, including exports, staging tables, backup files, transfer channels, and monitoring tools. Confirm that personal information is removed or masked from failure messages. Test whether an operator with access to logs can see full addresses, identity documents, account numbers, or authentication data.
Keep an audit trail for every test run. Record the script version, source snapshot, target version, configuration, test data set, start and finish times, operator, results, exceptions, and approvals. Teams seeking an independent review can draw on testing specialists to assess migration controls, automation coverage, and release readiness.
Automate Regression And Signoff
Automate repeatable checks so every script change triggers the same validation suite. Useful checks include schema compatibility, row counts, null thresholds, referential integrity, data type rules, reconciliation queries, duplicate detection, and comparison of critical fields. Store results with the build or release record rather than leaving them in a local spreadsheet.
Include migration tests in the delivery pipeline where the tooling supports it. A pull request that changes a transformation rule should run unit tests against representative fixtures, followed by integration tests against a disposable database. Larger volume tests can run on a scheduled basis, while security and rollback rehearsals should occur before each major release.
Signoff should reflect evidence from technical, business, security, and operational stakeholders. A clear go/no-go review should cover known variances, accepted risks, rollback timing, support rosters, monitoring dashboards, and the decision authority for stopping the cutover. For organisations modernising Microsoft platforms, an independent testing capability review can help connect migration assurance with broader Agile and DevOps practices.
Use the final rehearsal to validate the runbook from start to finish. Include environment preparation, backups, communications, access checks, migration execution, reconciliation, defect handling, and post-release monitoring. If an operator cannot follow the instructions without relying on tribal knowledge, the process is not ready for production.
Apply these checks to your next migration as a practical release gate: profile the data, automate reconciliation, rehearse failure, protect sensitive information, and require evidence-based signoff before cutover. A well-tested migration script is valuable, but a repeatable assurance process is what protects business continuity and customer trust.