Merge pull request #346 from tony1223/bug/343-fee_currency_length

This commit is contained in:
Yo-An Lin 2021-12-11 10:57:17 +08:00 committed by GitHub
commit 0c7bbba675
5 changed files with 93 additions and 0 deletions

View File

@ -562,6 +562,14 @@ Then run the following command to compile the migration files into go files:
make migrations
```
or
```shell
rockhopper compile --config rockhopper_mysql.yaml --output pkg/migrations/mysql
rockhopper compile --config rockhopper_sqlite.yaml --output pkg/migrations/sqlite3
git add -v pkg/migrations && git commit -m "compile and update migration package" pkg/migrations || true
```
If you want to override the DSN and the Driver defined in the YAML config file, you can add some env vars in your dotenv file like this:

View File

@ -0,0 +1,9 @@
-- +up
-- +begin
ALTER TABLE trades CHANGE fee_currency fee_currency varchar(10) NOT NULL;
-- +end
-- +down
-- +begin
ALTER TABLE trades CHANGE fee_currency fee_currency varchar(4) NOT NULL;
-- +end

View File

@ -0,0 +1,8 @@
-- +up
-- +begin
-- +end
-- +down
-- +begin
-- +end

View File

@ -0,0 +1,34 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upUpdateFeeCurrencyLength, downUpdateFeeCurrencyLength)
}
func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE trades CHANGE fee_currency fee_currency varchar(10) NOT NULL;")
if err != nil {
return err
}
return err
}
func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE trades CHANGE fee_currency fee_currency varchar(4) NOT NULL;")
if err != nil {
return err
}
return err
}

View File

@ -0,0 +1,34 @@
package sqlite3
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upUpdateFeeCurrencyLength, downUpdateFeeCurrencyLength)
}
func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "")
if err != nil {
return err
}
return err
}
func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "")
if err != nil {
return err
}
return err
}