Skip to content
Pedro Villa
← Back to posts

A migration engine, not a migration by hand

Published: · 2 min read

The nine stages of the SQL Server to PostgreSQL migration engine, from source inventory through to cutover

I migrated a database from SQL Server to PostgreSQL in a month, with AI. Without it the process would have taken considerably longer.

The challenge

  • Billions of rows and hundreds of stored procedures carrying business logic.
  • Several applications, services and reports depending on that database.
  • All of it in continuous production: the change had to be invisible.

Moving the data is only the visible part

The hard part is that the two engines behave differently in details the code had taken for granted:

  • SQL Server treats “ABC” and “abc” as the same value, and PostgreSQL does not.
  • One reads data another transaction has not committed yet, and the other does not.
  • A connection SQL Server recovered on its own stays held in PostgreSQL.
  • Queries that are fast on one engine can be slow on the other.

Building an engine instead of migrating piece by piece

That was the key decision. Every stage is repeatable, verifiable, and has a gate that blocks progress when something does not add up:

  1. Source inventory. Every object catalogued with a fingerprint.
  2. Data sweep. Finds, in the real data, what the new engine would treat differently.
  3. Schema generation. DDL generated from the source catalog and versioned, not written by hand.
  4. Logic translation. Procedures converted into functions under uniform rules.
  5. Structural validation. Catalogs from both engines, with zero differences.
  6. Behavioural validation. Cases compared row by row against the source.
  7. Compatibility layer. Applications do not rewrite their data access.
  8. Certified bulk load. Parallel and streaming, with verified counts.
  9. Cutover. Sequences, indexes, statistics and a step by step runbook.

If the source changes or a new rule appears, I run the engine again instead of redoing the work.

The result

  • Every function was compared row by row against the original procedure, and every difference was explained.
  • The data was certified before and after the load, with no differences between the two engines.
  • The applications did not rewrite their data access, and rolling back was a parameter change.

My standard was total fidelity: the same result as the original, including its historical defects, which I documented and migrated as they were so they could be fixed afterwards.

Where AI came in

  • It built the engine’s tooling: generators, comparators and certifiers.
  • It translated the logic under consistent rules, instead of hundreds of handcrafted translations.
  • It validated adversarially, with mutation testing and row by row comparison.
  • It found the hard problems, and each one became a rule in the engine.
  • It diagnosed the post-cutover incidents in hours.

The difference was not only speed. AI let me build the engine rather than migrate by hand, and that leaves me a reusable capability for the next database.

In short

In the end it was about handing the AI my judgement from previous migrations in order to amplify myself: it applied the same thing I would have done migrating manually.

Have you been through an engine migration? Tell me how it went.