Existing databases
Adopting a database that is already in production.
When a database already has its schema, you do not want to run your initial changes against it. Baseline records them as applied without executing them.
- Script the current schema as your first change(s), e.g. with SSMS, SqlPackage or Badger SQL. Keep them as the real history for new environments.
- Tag that point:
bsm tag baseline. - For each existing database:
bsm baseline --to @baseline -e prod. - From here on, add changes normally. New, empty databases run the full plan, including the initial changes.
bsm add initial-schema --irreversible # paste the scripted schema into deploy.sql
bsm tag baseline
bsm baseline --to @baseline -e prod
bsm status -e prod # initial-schema shown as (baseline)
Baseline only works on a database with no deployed changes, takes the deploy lock, records the environment, and writes a schema fingerprint so later drift is detected.
Coming from Flyway, DbUp or grate
For Flyway, DbUp, grate, RoundhousE and Sqitch, bsm import does the conversion and bsm baseline --from reads each database's history for you; see Moving from other tools. For anything else:
- Convert your versioned scripts into changes (one folder each) in their existing order, or collapse history into one
initial-schemachange. - Write revert scripts for the changes you might want to undo; mark the rest
!irreversible. - Move repeatable/"anytime" scripts into
repeatable/. - Replace placeholders such as
${name}(Flyway) with{name}or keep$(name). - Baseline each existing database. The old tool's history table can stay; bsm uses its own
bsmschema.