kadena-io / chainweb-data

Data ingestion for Chainweb.
BSD 3-Clause "New" or "Revised" License
14 stars 8 forks source link

Prepare for the script based migrations #102

Closed enobayram closed 1 year ago

enobayram commented 1 year ago

This commit extends the current schema migration with the transition release phase of the upcoming script-based schema migrations.

The full transition plan can be found at: https://github.com/kadena-io/chainweb-data/issues/101

enobayram commented 1 year ago

Here's how I verified that this PR enables the migration transition plan outlined in #101

Before running a chainweb-data binary with this PR, I've dropped down to the cabal repl for the chainweb-data executable and performed the following:

$ cabal repl exec/Main.hs
*Main> conn <- connectPostgreSQL "postgresql:///chainweb_data?host=/var/run/postgresql/"
*Main> Mg.runMigration (Mg.MigrationContext (Mg.MigrationValidation Mg.MigrationInitialization) False conn)
MigrationError "No such table: schema_migrations"

This MigrationError correctly identifies a pre-transition database state.

Then I ran chainweb-data in fill mode:

$ /nix/store/n6034m4g78410sqhlzhv42csb5ri0d4y-chainweb-data-2.0.1/bin/chainweb-data ... fill
2022-12-06T06:29:28.717Z [Info] [] Using database: PGString "postgresql:///chainweb_data?host=/var/run/postgresql/"
...
2022-12-06T06:29:28.827Z [Info] [] No database migration needed.  Continuing...
2022-12-06T06:29:28.827Z [Info] [] Adding height index on transactions table
...
2022-12-06T06:29:28.829Z [Info] [] Initializing the incremental migrations table
2022-12-06T06:29:28.856Z [Info] [] Initialized migrations
2022-12-06T06:29:28.856Z [Info] [] DB Tables Initialized
...

And here's how I've observed the transitioned state of the database after the migration:

*Main> Mg.runMigration (Mg.MigrationContext (Mg.MigrationValidation Mg.MigrationInitialization) False conn)
MigrationSuccess