Docs/Get started/Import an existing database
OSS

Import an existing database

Most databases predate the tool that manages them. Baselining tells DBLift that everything up to a given version already exists, so it starts tracking from there instead of trying to create what is already there.

Step 1. See what DBLift sees

Point DBLift at the database and look before you touch anything. On a database with no history table, every local migration shows as pending.

dblift info

Step 2. Set the baseline

Pick the version that describes the schema as it stands today, and record it.

dblift baseline --baseline-version=1.0.0 --baseline-description="Existing production database"
FlagDescription
--baseline-versionVersion to baseline the database at. Required.
--baseline-descriptionDescription for the baseline version. Worth filling in — it is what a reviewer reads a year from now.

This writes a single row to the schema history table, creating it if needed. Nothing in your schema is touched.

Step 3. Apply what comes after

Only migrations above the baseline version run. Preview first, as always.

dblift migrate --dry-run --show-sql
dblift migrate

Choose the version deliberately

Migrations at or below the baseline will never run on this database. Baseline too high and you silently skip changes the schema has not actually received; too low and the next migrate tries to create objects that already exist. Confirm against the real schema before you pick.

Coming from Flyway?

Do not baseline. dblift import-flyway reads your existing flyway_schema_history table and carries the real history across, so you keep every applied version rather than collapsing them into one baseline row. See Move from Flyway.

On this page