Database Migration:
From Legacy Systems to Modern Infrastructure

Confidential — Public Healthcare · Core Applications

Snapshot
Duration
Six months for the first estate; the second ran on the same method
Scope
Stored procedures, and the Java and .NET code that calls them, moving from Sybase to PostgreSQL
Role
Migration engineering — conversion pipeline, coverage tooling, parallel-run discipline
Roles involved
DBA, stored-procedure developers, Java and .NET engineers, QA, application owners
Deliverables
Conversion pipeline, exception knowledge base, coverage and comparison tooling, per-procedure reports, retirement roadmap
NDA
Client and system names withheld. Procedure text, schema and data are not reproduced; volumes and method are as delivered.
120,000
Lines of Sybase stored procedure converted and validated
6 months
To convert and validate that estate
210+
Transaction cases running in parallel on the new engine
100%
Stored-procedure test coverage, written into the requirement

Problem

A stored procedure is not a file. It is a business rule with a control flow, a set of dependencies it never declares, and a habit of calling other procedures that call others. In a system that has been in service for a decade, the procedures are where the business logic actually lives — not in the documentation, which describes what the system was meant to do, but in the branches someone added for a case that never appeared in any specification.

Moving 120,000 lines of that from Sybase to PostgreSQL is not a syntax problem that a converter solves. It is an evidence problem. For each procedure the question is: can you show that the new one does the same thing as the old one, on the paths that matter? With a requirement of full coverage, “it compiles and the happy path works” is not an answer.

The failure mode is specific and quiet. A converter does not refuse. It produces something that parses, and the difference between parsing and equivalent is a branch nobody exercised.

Approach

Four decisions.

Route each construct to a tool that can actually handle it. Bulk DML syntax goes through a rule-based converter. SQL embedded in Java goes through a parser-driven re-expression rather than substring replacement, so the statement is understood before it is rewritten. Constructs no rule covers go to a model working from a knowledge base of already-solved cases — as a proposal, never as a verdict. What remains goes to a person. The routing is explicit because the whole point is to know which of the four produced any given line.

Treat the exception list as the deliverable. Every construct the converter could not handle is a known unknown. The list of them, each with its resolution, is a reusable asset rather than a by-product, and it is the single reason a second estate costs less than the first.

Count branch combinations, not lines. A procedure with two nested decisions has paths that line coverage never visits. The instrument compiles a shadow procedure that records which branches executed, then compares the combination count in source against the combination count in target. A difference in the count is a conversion defect before any test is written.

Harvest the inputs instead of inventing them. Test data written by hand tests the paths its author thought of. The harness collects real argument sets from the system's own logs and replays them against both engines — which is the only way to reach full coverage without writing thousands of cases nobody will maintain.

Figure 1 — Four routes, one gate

Four conversion routes and one gateOne estate, four kinds of construct, four different tools — and a single gate at the endClassify firstThe route is chosen by what the construct is, not by which tool is available.Rule-basedSQLinesBulk DML, syntax, datatypes, views, indexes.Deterministic, and itreports what it failed on.Parser-drivenAntlr4 → JPASQL embedded in Java.Re-expressed, notstring-replaced — thestatement still parses.Knowledge base+ modelConstructs no rulecovers. Retrieves asolved case, proposes arewrite. Never decides.HumanReviewThe residue of theother three. Also thesign-off on every linethe first three produced.One gateBranch-combination coverage, plus a three-level comparison of old and new.Nothing above counts as converted until it passes here — including what a person wrote by hand.The failure mode of a converter is silence: it produces something that parses. The gate exists because parsing is not the same as equivalent.Route names and tool choices follow the delivered conversion pipeline; volumes differ by construct.

Figure 2 — What full coverage of a procedure actually means

What full coverage of a stored procedure meansA nested branch has paths that line coverage never reachesTWO DECISIONS, THREE OUTCOMES1IF@mode = 'A'2ELSE IF@mode = 'B'3INSERT …4UPDATE …5DELETE …Eight paths, not five statements:1-31-41-52-32-42-512THREE WAYS TO COUNTBranch combinationthe only count that proves two branches ran togetherBranchthe decision was taken both ways, separatelyLinea statement executed, in some orderCount the paths in source and in target.A difference in the number of combinations is a conversiondefect before a single test case is written.Line coverage of a nested procedure can read 100% while a combination has never run. That is the number a migration can be signed off on and still be wrong.Illustrative procedure. The combination set, the three coverage dimensions and the source-versus-target path count are the delivered method.

How it was run

Six months, in phases, with the estate split so that each phase ended in something runnable rather than in a percentage. A procedure was counted as converted when it had been through the gate — coverage, comparison, sign-off — not when it had been through the converter.

The second estate ran in parallel on the same method: more than two hundred transaction cases executing against PostgreSQL while the old engine was still in service, which turns the migration from a switch into a comparison that can be read.

Comparison was layered deliberately. A result set proves the calculation; table data proves the write; and the execution plan proves the new engine is not quietly scanning a table the old one indexed. Each layer catches a different kind of mistake, and only the third one catches the mistakes that survive functional testing and appear in production under load.

Nested procedures got their own treatment: argument capture at the call boundary, so a child procedure could be tested on its own rather than only through its parent — the difference between testing a procedure and testing whatever happens to reach it.

Figure 3 — Proving equivalence on a live workload

Proving equivalence on a live workloadThe test inputs were not written by hand — they were taken from the system's own logsHarvestReal argument sets are collected from production logs, so the cases that exist in the data are the cases that get tested.Sybase ASEthe engine in service todayPostgreSQLthe engine being migrated tosame inputTHREE COMPARISONS, EVERY CASEResult setsame columns, same values, same ordermust matchTable datachecksums after the same transactionmust matchExecution planthe query still finds an indexmust matchTwo engines agreeing on a result set is the weakest form of equivalence. The plan is the one that tells you the new engine is not silently scanning a table the old one indexed.

What we delivered

01
Conversion pipeline
Rule-based, parser-driven and assisted routes, with the choice of route recorded per construct.
02
Exception knowledge base
Every pattern the rules missed, and how it was resolved — the asset that made the second estate cheaper.
03
Coverage instrumentation
Shadow procedures that record which branches executed, so coverage is observed rather than claimed.
04
Three-level comparison
Result set, table data and execution plan, run for every case against both engines.
05
Per-procedure reports
For each procedure: paths counted, paths covered, what was compared, where the engines disagreed.
06
Retirement roadmap
A phased plan for switching off the legacy engine once the parallel period had done its work.

System names, schema and procedure text are withheld. Volumes and method are as delivered.

Impact

120,000 lines in six months, and a second estate running more than two hundred transaction cases in parallel on the new engine.

The line count is the least interesting number on this page. What matters is that for each converted procedure there is a report saying which branches were executed, what was compared, and where the two engines disagreed. That is the difference between a migration and a rewrite you hope is equivalent — and it is the only thing that would survive being asked to prove it.

The exception knowledge base outlived the project. It is now the starting position for the next legacy system, which is how a one-off exercise turns into a practice.

CONTACT US

We provide a custom made service for just drop us a line.
We would be glad to have feedback from you.