-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compile and update migration package
- Loading branch information
Showing
8 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mysql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginLoans, downMarginLoans) | ||
|
||
} | ||
|
||
func upMarginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_loans`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `transaction_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`transaction_id`)\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginLoans(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 `margin_loans`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mysql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginRepays, downMarginRepays) | ||
|
||
} | ||
|
||
func upMarginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_repays`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `transaction_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`transaction_id`)\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginRepays(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 `margin_repays`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mysql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginInterests, downMarginInterests) | ||
|
||
} | ||
|
||
func upMarginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_interests`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `principle` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `interest` DECIMAL(20, 16) UNSIGNED NOT NULL,\n `interest_rate` DECIMAL(20, 16) UNSIGNED NOT NULL,\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`)\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginInterests(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 `margin_interests`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
34 changes: 34 additions & 0 deletions
34
pkg/migrations/mysql/20220531015005_margin_liquidations.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mysql | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginLiquidations, downMarginLiquidations) | ||
|
||
} | ||
|
||
func upMarginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_liquidations`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `order_id` BIGINT UNSIGNED NOT NULL,\n `is_isolated` BOOL NOT NULL DEFAULT false,\n `average_price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `executed_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `side` VARCHAR(5) NOT NULL DEFAULT '',\n `time_in_force` VARCHAR(5) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY (`order_id`, `exchange`)\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginLiquidations(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 `margin_liquidations`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package sqlite3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginLoans, downMarginLoans) | ||
|
||
} | ||
|
||
func upMarginLoans(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_loans`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `transaction_id` INTEGER NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginLoans(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 `margin_loans`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package sqlite3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginRepays, downMarginRepays) | ||
|
||
} | ||
|
||
func upMarginRepays(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_repays`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `transaction_id` INTEGER NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n -- quantity is the quantity of the trade that makes profit\n `principle` DECIMAL(16, 8) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginRepays(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 `margin_repays`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package sqlite3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginInterests, downMarginInterests) | ||
|
||
} | ||
|
||
func upMarginInterests(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_interests`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `asset` VARCHAR(24) NOT NULL DEFAULT '',\n `isolated_symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `principle` DECIMAL(16, 8) NOT NULL,\n `interest` DECIMAL(20, 16) NOT NULL,\n `interest_rate` DECIMAL(20, 16) NOT NULL,\n `time` DATETIME(3) NOT NULL\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginInterests(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 `margin_interests`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
34 changes: 34 additions & 0 deletions
34
pkg/migrations/sqlite3/20220531015005_margin_liquidations.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package sqlite3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/c9s/rockhopper" | ||
) | ||
|
||
func init() { | ||
AddMigration(upMarginLiquidations, downMarginLiquidations) | ||
|
||
} | ||
|
||
func upMarginLiquidations(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { | ||
// This code is executed when the migration is applied. | ||
|
||
_, err = tx.ExecContext(ctx, "CREATE TABLE `margin_liquidations`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(24) NOT NULL DEFAULT '',\n `order_id` INTEGER NOT NULL,\n `is_isolated` BOOL NOT NULL DEFAULT false,\n `average_price` DECIMAL(16, 8) NOT NULL,\n `price` DECIMAL(16, 8) NOT NULL,\n `quantity` DECIMAL(16, 8) NOT NULL,\n `executed_quantity` DECIMAL(16, 8) NOT NULL,\n `side` VARCHAR(5) NOT NULL DEFAULT '',\n `time_in_force` VARCHAR(5) NOT NULL DEFAULT '',\n `time` DATETIME(3) NOT NULL\n);") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func downMarginLiquidations(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 `margin_liquidations`;") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |