alphagov/trade-tariff-backend — pull request #91 by sauliusg (2013-07-30 07:10:33+00:00)
Title: Data migrations

This change is for https://www.pivotaltracker.com/story/show/43132661

Separates schema migrations from data migrations, as schema migrations with data are usually problematic when we're recreating database snapshot from scratch. They fill in data before Taric and CHIEF imports and that can cause integrity issues later. Data migrations should be run after all schema changes and data imports are applied.

This adds several new rake commands:

Check current db state:

```
bundle exec rake db:data:status
[APPLIED] Convert MeasurementUnit code from ASX to ASV
[APPLIED] Rename San Marino to Italy on national measures: This is for excluded geographical areas. Related to commit #3951ff024bc , invalid original data.
[APPLIED] Remove national measures of type SPL
[APPLIED] Fix CHIEF le_tsmps
[APPLIED] Populates HiddenGoodsNomenclature with data: Certain GoodsNomenclatures should be hidden in UK Tariff.
[APPLIED] Updates Footnote descriptions 04005 and 04018 with up to date data
[APPLIED] Add hydrocarbon oils footnote 05976
[APPLIED] Fix CHIEF hectolitre mappings
[APPLIED] Updates Footnote description 04003
```

Rollback last applied migration (based on timestamp in filename):

```
bundle exec rake db:data:rollback
[ROLLBACK] Updates Footnote description 04003
```

Apply all pending migrations:

```
bundle exec rake db:data:migrate
[APPLIED] Updates Footnote description 04003
```

Rollback and apply last migration:

```
bundle exec rake db:data:redo
[ROLLBACK] Updates Footnote description 04003
[APPLIED] Updates Footnote description 04003
```

Things to note/questions:

* These migrations rewrite 'history', as they are modifying oplog tables (for Taric related migrations).
* What should happen to current migrations that affect data? We cannot remove the files as Sequel will complain, but perhaps we can comment out the code inside? Editing applied migrations is not the best practice, but this is data related.