Migrations and transformation
Convert a model to another dialect with every loss reported, and migrate a database with its data into PostgreSQL.
Moving to another database system has two parts: the model, and the data. databee keeps them apart so each can be reviewed.
Transform the model
databee analyze compatibility --to postgres
databee transform --to postgres --into ../shop-pg
databee analyze fit
analyze compatibility prints the conversion report without writing anything. transform writes a new project for the target dialect (postgres, mysql, sqlite or mongodb) into --into, with the same model IDs. MySQL, MariaDB, SQLite, SQL Server and MongoDB to PostgreSQL is the thorough direction; PostgreSQL to MySQL or SQLite is best effort. SQL Server is a source only, never a target.
Each conversion in the report is one of:
| Class | Meaning |
|---|---|
exact |
Same meaning in the target |
equivalent |
Different spelling, same behaviour |
lossy |
Something is lost; the reason says what |
manual |
A decision is open; the report names the decision key and the allowed values |
unsupported |
The target has no counterpart |
Reports have a code DB-TRF-*, the object, the project file and the JSON path. Open decisions give exit code 1 and the new model holds placeholders until they are made.
Decisions live in mapping files
Decisions go into mappings/<source>-to-<target>.toml of the project, globally under [defaults] and per column under [columns."schema.table.column"]; a JSON Schema is in .databee/schemas/mapping.schema.json. For example, from the SQL Server fixture of the test suite:
[defaults]
case_insensitive_unique = "citext"
money = "numeric"
rowversion = "bytea"
[columns."shop.category.node"]
target_type = "text"
Decisions that change data include TINYINT(1) as boolean or smallint, BIGINT UNSIGNED, zero dates and the time zone of DATETIME. databee asks; it does not guess. Documents and rows are converted the same way: each embedded object, array, ObjectId, multi-type field and inferred reference is a decision, with a recommendation attached.
Which system fits
databee analyze fit scores the model for PostgreSQL, MySQL/MariaDB, SQLite, MongoDB and SQL Server and prints the reason of every deduction, never a bare number. A domain can describe how the data is used with a line such as access: read-heavy or access: high-concurrency, which the scoring takes into account.
Migrate with data
A migration copies the data of a MySQL, MariaDB, SQLite or SQL Server database into an empty PostgreSQL database. --project is the transformed project, and --from and --to are connection profile names or URLs.
databee --project ../shop-pg migrate plan --from legacy --to target --name first
databee --project ../shop-pg migrate preview first --from legacy
databee --project ../shop-pg migrate approve first # needs a terminal
databee --project ../shop-pg migrate execute first --from legacy --to target
databee --project ../shop-pg migrate verify first --from legacy --to target
planwritesmigrations/<name>.jsonwith a hash: the schema, one data step per table in load order, then foreign keys, indexes and sequence values. It refuses open decisions and a source that changed since the transformation (DB-MIG-001).previewshows steps, row counts and risks.approverecords a human approval for the plan hash.executecopies the data in batches (10,000 rows by default,--batch-sizeonplan) from one consistent snapshot, applying the value rules.resumecontinues an interrupted run after the last committed batch. Tables without a usable key are copied again.verifycompares row counts, checksums over normalised values, NULL counts, foreign keys and sequence state. Differences areDB-MIG-100toDB-MIG-104and exit code 1.
The source must not change while a migration runs. MongoDB documents can be converted at model level, but running the document-to-row rules against databases is not part of this version.