A MySQL to PostgreSQL migration tool with its own verifier, plus a salvage or rebuild assessment of a real open source PHP/CodeIgniter till system.
Real output of tillcarry migrate && tillcarry verify against the seeded Open Source Point of Sale
3.3.9 schema (sample data, local docker); full run in docs/demo-captured.txt.
The tool runs against that system's real schema and a seeded sample dataset. The dataset is built to include the awkward rows a decade of shop data actually has. Everything was built and run on a public open source project in a local Docker stack.
The assessment (docs/assessment.md): a "salvage or rebuild?" review of
opensourcepos/opensourcepos 3.3.9 (MIT licensed).
It covers the architecture, the database and the dependencies checked against public CVE advisories. It lists offline
security leads with file:line citations. Test coverage is measured at 0.34% of lines, from running
the project's own PHPUnit suite with coverage on. Each area gets a reuse, refactor or replace decision, and a phased
modernization plan carries effort ranges. Every number in it was run, not guessed.
The migration (src/tillcarry/): reads OSPOS's own MySQL schema and builds a type-mapped PostgreSQL
schema. Decimal money stays exact, tinyint(1) becomes boolean only where the data proves it is
one, and case-insensitive unique keys map to citext. It then copies the data. Rows whose foreign
key parent is missing go into a _tillcarry_rejects table with the reason, and none are dropped silently.
Every zero or impossible date it had to fix is logged.
A separate verifier trusts none of the migrator's own claims. It replays the foreign keys over the source data itself and checksums every column. It sums every money column to the cent and samples rows field by field. It also checks every foreign key, index and sequence in the target.
Needs Docker and Python 3.11+.
git clone <this repo> && cd tillcarry
python -m venv .venv && . .venv/Scripts/activate # or source .venv/bin/activate
pip install -e ".[dev]"
docker compose up -d --wait # MySQL 8.4 on 13307, PostgreSQL 17 on 15432, local only
tillcarry seed # loads the OSPOS 3.3.9 schema into MySQL, fills it with sample data
tillcarry migrate # copies MySQL -> PostgreSQL, builds schema "ospos"
tillcarry verify # proves nothing was lost; exits 1 on any mismatch$ tillcarry seed
seeded 11218 rows in 39 tables (seed 20261030); manifest: out\seed-manifest.json
emoji into the utf8mb3 schema: {'result': 'rejected', 'error': "1366: Incorrect string value..."}
$ tillcarry migrate
TOTAL 11218 11164 54 14
Swapped in as schema 'ospos'. Previous schema kept as 'ospos_prev'.
$ tillcarry verify
rows: source 11218 = loaded 11164 + quarantined 54
columns checksummed: 277 rows sampled field by field: 2459
payments total in PostgreSQL: 384480.49 (quarantined payments: 739.61)
279/279 checks passed
The run read 11,218 source rows. It loaded 11,164 and quarantined 54, each with a logged reason and none dropped. It coerced and logged 14
zero or impossible dates, and all 279 independent checks passed. Run tillcarry verify
again after deliberately damaging one row, one cent or one character in PostgreSQL and it fails. That
control is a permanent test (tests/test_integration.py, the test_control_* functions), not a one off
demo.
python -m pytest -q # unit tests, no database needed, ~75 tests
docker compose up -d --wait && python -m pytest -q -m integration # the full pipeline against the real containersThe unit tests cover the type mapping rules: every MySQL type the schema uses, the boolean/smallint decision and zero-date handling. They also cover the verifier's own canonical forms, independently of the migrator.
The integration suite seeds, migrates and verifies. It runs twice to prove it is idempotent, then rolls back. After that it deliberately breaks the target eight different ways: a deleted row, a wrong cent, a changed character, two values swapped between rows, an extra row, a forgotten quarantine entry, a dropped foreign key and a stale sequence. The verifier has to notice every one. The suite then heals the target and reverifies.
tillcarry rollback # swaps the previous PostgreSQL schema back in; safe to run migrate again afterEach migrate run builds the new schema alongside the old one. It renames the new one into place inside one
transaction and keeps the schema it replaces as ospos_prev. A rollback is two renames, not a restore
from backup. Running migrate again after a rollback is safe (idempotent), since it rebuilds from the current
MySQL source the same way every time.
flowchart LR
MY[(MySQL 8.4<br/>OSPOS 3.3.9 schema<br/>seeded data)] -->|introspect.py| PLAN[plan.py<br/>type map + FK repair]
PLAN --> DDL[ddl.py]
DDL -->|CREATE TABLE in ospos_next| PG[(PostgreSQL 17)]
MY -->|COPY, one read-only snapshot| PG
PG -->|orphan sweep, FKs, sequences| PG
PG -->|rename ospos_next -> ospos| PG
MY -.->|replay FKs over source| VERIFY[verify.py]
PG -.->|checksums, sums, sample, FK/index/sequence checks| VERIFY
The schema has one foreign key (ospos_sales_items_taxes to ospos_sales_items) whose declared parent
column, sale_id alone, is not actually unique. MySQL permits this because it only requires the
referenced columns to be a prefix of some index, not a full key. PostgreSQL requires a true
primary or unique key. The migration documents and repairs this (FK_REPLACEMENTS in src/tillcarry/plan.py)
rather than silently dropping the relationship.
The seeded data plants rows that pass the loose
MySQL version of the key and fail the correct one. They are there to prove the repair is doing something
real (docs/assessment.md section 3 has the full story).
Built and run on seeded sample data. A shop's own export can bring data shapes beyond this seed.
The type map raises a ValueError on an unrecognised MySQL type. That is deliberate, because it refuses to guess rather than
silently mis-map something new.
The security section of the assessment is offline. Its leads are grep based, read
and judged by hand, with one narrow, consented control test. Full limits list: docs/assessment.md section 10.
Python 3.11, PyMySQL, psycopg3, pytest; MySQL 8.4 and PostgreSQL 17 in Docker. The assessment's own
metrics and security-lead scripts are plain standard library Python (scripts/assessment/).
MIT (LICENSE). Schema files under schema/ are derived from opensourcepos/opensourcepos (also MIT);
see NOTICE.