mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add migration files
This commit is contained in:
parent
00109eb464
commit
4e9973681a
28
migrations/mysql/20210301140656_add_withdraws_table.sql
Normal file
28
migrations/mysql/20210301140656_add_withdraws_table.sql
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `withdraws`
|
||||||
|
(
|
||||||
|
`gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`exchange` VARCHAR(24) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- asset is the asset name (currency)
|
||||||
|
`asset` VARCHAR(10) NOT NULL,
|
||||||
|
|
||||||
|
`address` VARCHAR(64) NOT NULL,
|
||||||
|
`network` VARCHAR(32) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
`amount` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`txn_id` VARCHAR(64) NOT NULL,
|
||||||
|
`txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,
|
||||||
|
`txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',
|
||||||
|
`time` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`gid`),
|
||||||
|
UNIQUE KEY `txn_id` (`exchange`, `txn_id`)
|
||||||
|
);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
-- +begin
|
||||||
|
DROP TABLE IF EXISTS `withdraws`;
|
||||||
|
-- +end
|
26
migrations/mysql/20210307201830_add_deposits_table.sql
Normal file
26
migrations/mysql/20210307201830_add_deposits_table.sql
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `deposits`
|
||||||
|
(
|
||||||
|
`gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
`exchange` VARCHAR(24) NOT NULL,
|
||||||
|
|
||||||
|
-- asset is the asset name (currency)
|
||||||
|
`asset` VARCHAR(10) NOT NULL,
|
||||||
|
|
||||||
|
`address` VARCHAR(64) NOT NULL DEFAULT '',
|
||||||
|
`amount` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`txn_id` VARCHAR(64) NOT NULL,
|
||||||
|
`time` DATETIME(3) NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`gid`),
|
||||||
|
UNIQUE KEY `txn_id` (`exchange`, `txn_id`)
|
||||||
|
);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
DROP TABLE IF EXISTS `deposits`;
|
||||||
|
-- +end
|
36
migrations/sqlite3/20210301140656_add_withdraws_table.sql
Normal file
36
migrations/sqlite3/20210301140656_add_withdraws_table.sql
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `withdraws`
|
||||||
|
(
|
||||||
|
`gid` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`exchange` VARCHAR(24) NOT NULL DEFAULT '',
|
||||||
|
|
||||||
|
-- asset is the asset name (currency)
|
||||||
|
`asset` VARCHAR(10) NOT NULL,
|
||||||
|
|
||||||
|
`address` VARCHAR(64) NOT NULL,
|
||||||
|
`network` VARCHAR(32) NOT NULL DEFAULT '',
|
||||||
|
`amount` DECIMAL(16, 8) NOT NULL,
|
||||||
|
|
||||||
|
`txn_id` VARCHAR(64) NOT NULL,
|
||||||
|
`txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,
|
||||||
|
`txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',
|
||||||
|
`time` DATETIME(3) NOT NULL
|
||||||
|
);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
CREATE UNIQUE INDEX `withdraws_txn_id` ON `withdraws` (`exchange`, `txn_id`);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
DROP INDEX IF EXISTS `withdraws_txn_id`;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
DROP TABLE IF EXISTS `withdraws`;
|
||||||
|
-- +end
|
||||||
|
|
31
migrations/sqlite3/20210307201830_add_deposits_table.sql
Normal file
31
migrations/sqlite3/20210307201830_add_deposits_table.sql
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
-- +up
|
||||||
|
-- +begin
|
||||||
|
CREATE TABLE `deposits`
|
||||||
|
(
|
||||||
|
`gid` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`exchange` VARCHAR(24) NOT NULL,
|
||||||
|
|
||||||
|
-- asset is the asset name (currency)
|
||||||
|
`asset` VARCHAR(10) NOT NULL,
|
||||||
|
|
||||||
|
`address` VARCHAR(64) NOT NULL DEFAULT '',
|
||||||
|
`amount` DECIMAL(16, 8) NOT NULL,
|
||||||
|
`txn_id` VARCHAR(64) NOT NULL,
|
||||||
|
`time` DATETIME(3) NOT NULL
|
||||||
|
);
|
||||||
|
-- +end
|
||||||
|
-- +begin
|
||||||
|
CREATE UNIQUE INDEX `deposits_txn_id` ON `deposits` (`exchange`, `txn_id`);
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
|
||||||
|
-- +down
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
DROP INDEX IF EXISTS `deposits_txn_id`;
|
||||||
|
-- +end
|
||||||
|
|
||||||
|
-- +begin
|
||||||
|
DROP TABLE IF EXISTS `deposits`;
|
||||||
|
-- +end
|
||||||
|
|
34
pkg/migrations/mysql/20210301140656_add_withdraws_table.go
Normal file
34
pkg/migrations/mysql/20210301140656_add_withdraws_table.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package mysql
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/c9s/rockhopper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddMigration(upAddWithdrawsTable, downAddWithdrawsTable)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func upAddWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||||
|
// This code is executed when the migration is applied.
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "CREATE TABLE `withdraws`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(64) NOT NULL,\n `network` VARCHAR(32) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(64) NOT NULL,\n `txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,\n `txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `txn_id` (`exchange`, `txn_id`)\n);")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func downAddWithdrawsTable(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 `withdraws`;")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
34
pkg/migrations/mysql/20210307201830_add_deposits_table.go
Normal file
34
pkg/migrations/mysql/20210307201830_add_deposits_table.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package mysql
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/c9s/rockhopper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddMigration(upAddDepositsTable, downAddDepositsTable)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func upAddDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||||
|
// This code is executed when the migration is applied.
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "CREATE TABLE `deposits`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL,\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(64) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(64) NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `txn_id` (`exchange`, `txn_id`)\n);")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func downAddDepositsTable(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 `deposits`;")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
44
pkg/migrations/sqlite3/20210301140656_add_withdraws_table.go
Normal file
44
pkg/migrations/sqlite3/20210301140656_add_withdraws_table.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package sqlite3
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/c9s/rockhopper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddMigration(upAddWithdrawsTable, downAddWithdrawsTable)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func upAddWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||||
|
// This code is executed when the migration is applied.
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "CREATE TABLE `withdraws`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(64) NOT NULL,\n `network` VARCHAR(32) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(64) NOT NULL,\n `txn_fee` DECIMAL(16, 8) NOT NULL DEFAULT 0,\n `txn_fee_currency` VARCHAR(32) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL\n);")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `withdraws_txn_id` ON `withdraws` (`exchange`, `txn_id`);")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func downAddWithdrawsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||||
|
// This code is executed when the migration is rolled back.
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `withdraws_txn_id`;")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `withdraws`;")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
44
pkg/migrations/sqlite3/20210307201830_add_deposits_table.go
Normal file
44
pkg/migrations/sqlite3/20210307201830_add_deposits_table.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package sqlite3
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/c9s/rockhopper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AddMigration(upAddDepositsTable, downAddDepositsTable)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func upAddDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||||
|
// This code is executed when the migration is applied.
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "CREATE TABLE `deposits`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL,\n -- asset is the asset name (currency)\n `asset` VARCHAR(10) NOT NULL,\n `address` VARCHAR(64) NOT NULL DEFAULT '',\n `amount` DECIMAL(16, 8) NOT NULL,\n `txn_id` VARCHAR(64) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "CREATE UNIQUE INDEX `deposits_txn_id` ON `deposits` (`exchange`, `txn_id`);")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func downAddDepositsTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
||||||
|
// This code is executed when the migration is rolled back.
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "DROP INDEX IF EXISTS `deposits_txn_id`;")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = tx.ExecContext(ctx, "DROP TABLE IF EXISTS `deposits`;")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user