Musa
Musa

Reputation: 583

Running flyway migration on a DB with existing tables

I am running flyway migrations on a postgres DB with existing tables. In doing so flyway threw this error

Found non-empty schema(s) "public" but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.

After reading the docs on baselineOnMigrate, all we need to do is toggle this to true and we should be able to complete the migrations.

Need clarity on enabling this feature: do we set FLYWAY_BASELINE_ON_MIGRATE to TRUE only once and when the schema history table is created we can turn it back to FALSE? Or do we have to persist the TRUE value?

Upvotes: 2

Views: 1901

Answers (1)

tonyd
tonyd

Reputation: 36

Yes, you'd set it only once. That approach is really only used where Flyway takes all its parameters from the configuration file...it is just intended for a single use (e.g. just for one specific copy of a database, out of many). Normally, you baseline from an action at the command line like this:

Flyway baseline  @FlywayArgs -baselineVersion='1.3.1' -baselineDescription='Existing version of MyDatabase'

This article is using a SQL Server database rather than Postgres but might give a good idea of how flyway baselines work: https://www.red-gate.com/hub/product-learning/flyway/flyway-baselines-and-consolidations.

Upvotes: 1

Related Questions