jackc / tern

The SQL Fan's Migrator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatic migrations in case of outdated version found in migration_scheme.

darkjian opened this issue · comments

commented

I have studied issues as far as I could, but I haven't found an answer to my question, sorry in advance if I was inattentive.

How can I implement the following task:

When the application is launched, the version of the last added migration file and the version in the database schema should be checked.
If they do not match, load all migrations from files starting with the version specified in the database.

Is it possible with tern now?

p.s. thank you very much for your efforts

It is possible, but you would need to wire the calls together. You could use the *Migrator.GetCurrentVersion method to see what the current version is then call *Migrator.Migrate if it is not the latest. See the Status and Migrate functions in main.go for examples of how the CLI tool uses them.