alphagov/trade-tariff-backend — pull request #93 by sauliusg (2013-08-01 15:28:29+00:00)
Title: Increase decimal size on QuotaBalanceEvents fields

We lost somes values during import because they were bigger than specified decimal size.

`quota_balance_events_oplog` contains only insert operations and these only come from Taric. So we just need to reimport quota balance events entries to fix this. I uploaded a snapshot called `quota_balance_events_fix.sql.bz2` which contans just the relevant entries for this table.

How to apply the fix:

1. Make a backup of current quota_balance_events_table

```
mysqldump --no-create-info quota_balance_events_oplog > quota_balance_events_backup.sql
```

2. Deploy migration.
3. Truncate the table. In MySQL prompt issue:

```
TRUNCATE quota_balance_events_oplog;
```

4. Import updated balance events entries:

```
mysql < quota_balance_events_fix.sql
```

5. Rollback database updates to safe date:

````
DATE=2013-07-30 bundle rake tariff:sync:rollback
````

Why is this needed? I created `quota_balance_events_fix.sql` on 1st of August and the last Taric update that I have is for 31st of July. So if this update is going to be applied on say 10th of August we will loose quota balance events entries between 31st and 10th of August by TRUNCATING the table. So we have to rollback to a safe date (30th of July) and reapply everything again.

6. Apply the updates again (or leave this to the cron job):

````
bundle exec rake tariff:sync:apply
````