mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add positions table migration
This commit is contained in:
parent
b1559bcbe3
commit
f0d500bbaa
26
migrations/mysql/20220307132917_add_positions.sql
Normal file
26
migrations/mysql/20220307132917_add_positions.sql
Normal file
|
@ -0,0 +1,26 @@
|
|||
-- +up
|
||||
CREATE TABLE `positions`
|
||||
(
|
||||
`gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
||||
`strategy` VARCHAR(32) NOT NULL,
|
||||
`strategy_instance_id` VARCHAR(64) NOT NULL,
|
||||
|
||||
`symbol` VARCHAR(20) NOT NULL,
|
||||
`quote_currency` VARCHAR(10) NOT NULL,
|
||||
`base_currency` VARCHAR(10) NOT NULL,
|
||||
|
||||
-- average_cost is the position average cost
|
||||
`average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,
|
||||
`base` DECIMAL(16, 8) NOT NULL,
|
||||
`quote` DECIMAL(16, 8) NOT NULL,
|
||||
|
||||
`trade_id` BIGINT UNSIGNED NOT NULL,
|
||||
`traded_at` DATETIME(3) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`gid`),
|
||||
UNIQUE KEY `trade_id` (`trade_id`)
|
||||
);
|
||||
|
||||
-- +down
|
||||
DROP TABLE IF EXISTS `positions`;
|
23
migrations/sqlite3/20220307132917_add_positions.sql
Normal file
23
migrations/sqlite3/20220307132917_add_positions.sql
Normal file
|
@ -0,0 +1,23 @@
|
|||
-- +up
|
||||
CREATE TABLE `positions`
|
||||
(
|
||||
`gid` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
||||
`strategy` VARCHAR(32) NOT NULL,
|
||||
`strategy_instance_id` VARCHAR(64) NOT NULL,
|
||||
|
||||
`symbol` VARCHAR(20) NOT NULL,
|
||||
`quote_currency` VARCHAR(10) NOT NULL,
|
||||
`base_currency` VARCHAR(10) NOT NULL,
|
||||
|
||||
-- average_cost is the position average cost
|
||||
`average_cost` DECIMAL(16, 8) NOT NULL,
|
||||
`base` DECIMAL(16, 8) NOT NULL,
|
||||
`quote` DECIMAL(16, 8) NOT NULL,
|
||||
|
||||
`trade_id` BIGINT NOT NULL,
|
||||
`traded_at` DATETIME(3) NOT NULL
|
||||
);
|
||||
|
||||
-- +down
|
||||
DROP TABLE IF EXISTS `positions`;
|
34
pkg/migrations/mysql/20220307132917_add_positions.go
Normal file
34
pkg/migrations/mysql/20220307132917_add_positions.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package mysql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/c9s/rockhopper"
|
||||
)
|
||||
|
||||
func init() {
|
||||
AddMigration(upAddPositions, downAddPositions)
|
||||
|
||||
}
|
||||
|
||||
func upAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||
// This code is executed when the migration is applied.
|
||||
|
||||
_, err = tx.ExecContext(ctx, "CREATE TABLE `positions`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(20) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `base` DECIMAL(16, 8) NOT NULL,\n `quote` DECIMAL(16, 8) NOT NULL,\n `trade_id` BIGINT UNSIGNED NOT NULL,\n `traded_at` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `trade_id` (`trade_id`)\n);")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func downAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||
// This code is executed when the migration is rolled back.
|
||||
|
||||
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
34
pkg/migrations/sqlite3/20220307132917_add_positions.go
Normal file
34
pkg/migrations/sqlite3/20220307132917_add_positions.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package sqlite3
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/c9s/rockhopper"
|
||||
)
|
||||
|
||||
func init() {
|
||||
AddMigration(upAddPositions, downAddPositions)
|
||||
|
||||
}
|
||||
|
||||
func upAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||
// This code is executed when the migration is applied.
|
||||
|
||||
_, err = tx.ExecContext(ctx, "CREATE TABLE `positions`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(20) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) NOT NULL,\n `base` DECIMAL(16, 8) NOT NULL,\n `quote` DECIMAL(16, 8) NOT NULL,\n `trade_id` BIGINT NOT NULL,\n `traded_at` DATETIME(3) NOT NULL\n);")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func downAddPositions(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||
// This code is executed when the migration is rolled back.
|
||||
|
||||
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `positions`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user