Skip to content

v2.1

Compare
Choose a tag to compare
@lukaszbudnik lukaszbudnik released this 11 Dec 23:20
30270bf

In v2.1 among internal tweaks a new functionality of verifying migrations was implemented.

This functionality is especially useful in detecting modifications to existing migrations. Without being able to spot modifications to once applied migrations in test envs one may risk issues when running in production.

Migrator is now:

  • storing migration contents and checksums in DB
  • verifying if checksums of disk migrations match those in DB - checksum verification is called for every apply and add tenant action (both in tool and server mode)

In order to upgrade migrator v2.0 to v2.1 the following steps are required:

  1. Add contents and checksum columns to migrator.migrator_migrations table

Execute manually or add as a new migration to your existing migrator v2.0:

alter table migrator.migrator_migrations add contents text;
alter table migrator.migrator_migrations add checksum varchar(64);
  1. Compute and store sha256 checksums in migrator.migrator_migrations table

The following script when run in base dir with migrations will generate update-checksums.sql containing sha256 SQL update statements.

#!/bin/bash

dirs=$(ls)

echo "" > update-checksums.sql

for dir in $dirs
do
  if [ -d $dir ]; then
    sha256sum ${dir}/* | awk -v OFS='' '{print "update migrator.migrator_migrations set contents='\'''\'', checksum = '\''",$1,"'\'' where filename = '\''",$2,"'\'';"}' | tee -a update-checksums.sql
  fi
done
  1. Execute update-checksums.sql

Depending on your DB:

psql -U $user -h $ip -p $port -d $database -f update-checksums.sql
mysql -u $user -h $ip -P $port -D $database < update-checksums.sql
sqlcmd -S "$ip,$port" -U $user -P $password -d $database -i update-checksums.sql