mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +00:00
Merge pull request #84 from c9s/fix/unique-index
fix unique index for binance self trade
This commit is contained in:
commit
2122bc9b15
15
migrations/20210118163847_fix_unique_index.sql
Normal file
15
migrations/20210118163847_fix_unique_index.sql
Normal file
|
@ -0,0 +1,15 @@
|
|||
-- +up
|
||||
-- +begin
|
||||
ALTER TABLE `trades` DROP INDEX `id`;
|
||||
-- +end
|
||||
-- +begin
|
||||
ALTER TABLE `trades` ADD UNIQUE INDEX `id` (`exchange`,`symbol`, `side`, `id`);
|
||||
-- +end
|
||||
|
||||
-- +down
|
||||
-- +begin
|
||||
ALTER TABLE `trades` DROP INDEX `id`;
|
||||
-- +end
|
||||
-- +begin
|
||||
ALTER TABLE `trades` ADD UNIQUE INDEX `id` (`id`);
|
||||
-- +end
|
43
pkg/migrations/20210118163847_fix_unique_index.go
Normal file
43
pkg/migrations/20210118163847_fix_unique_index.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/c9s/rockhopper"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rockhopper.AddMigration(upFixUniqueIndex, downFixUniqueIndex)
|
||||
}
|
||||
|
||||
func upFixUniqueIndex(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||
// This code is executed when the migration is applied.
|
||||
|
||||
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` DROP INDEX `id`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD INDEX UNIQUE `id` ON (`exchange`,`symbol`, `side`, `id`);")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func downFixUniqueIndex(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` DROP INDEX `id`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, "ALTER TABLE `trades` ADD INDEX UNIQUE `id` ON (`id`);")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user