From 7601f087869e6bca7ec42575d04d0270bf8e5459 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 31 May 2022 17:30:24 +0800 Subject: [PATCH] compile and update migration package --- .../mysql/20220531012226_margin_loans.go | 34 +++++++++++++++++++ .../mysql/20220531013327_margin_repays.go | 34 +++++++++++++++++++ .../mysql/20220531013542_margin_interests.go | 34 +++++++++++++++++++ .../20220531015005_margin_liquidations.go | 34 +++++++++++++++++++ .../sqlite3/20220531012226_margin_loans.go | 34 +++++++++++++++++++ .../sqlite3/20220531013327_margin_repays.go | 34 +++++++++++++++++++ .../20220531013541_margin_interests.go | 34 +++++++++++++++++++ .../20220531015005_margin_liquidations.go | 34 +++++++++++++++++++ 8 files changed, 272 insertions(+) create mode 100644 pkg/migrations/mysql/20220531012226_margin_loans.go create mode 100644 pkg/migrations/mysql/20220531013327_margin_repays.go create mode 100644 pkg/migrations/mysql/20220531013542_margin_interests.go create mode 100644 pkg/migrations/mysql/20220531015005_margin_liquidations.go create mode 100644 pkg/migrations/sqlite3/20220531012226_margin_loans.go create mode 100644 pkg/migrations/sqlite3/20220531013327_margin_repays.go create mode 100644 pkg/migrations/sqlite3/20220531013541_margin_interests.go create mode 100644 pkg/migrations/sqlite3/20220531015005_margin_liquidations.go diff --git a/pkg/migrations/mysql/20220531012226_margin_loans.go b/pkg/migrations/mysql/20220531012226_margin_loans.go new file mode 100644 index 000000000..1857a18ee --- /dev/null +++ b/pkg/migrations/mysql/20220531012226_margin_loans.go @@ -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 +} diff --git a/pkg/migrations/mysql/20220531013327_margin_repays.go b/pkg/migrations/mysql/20220531013327_margin_repays.go new file mode 100644 index 000000000..66582d977 --- /dev/null +++ b/pkg/migrations/mysql/20220531013327_margin_repays.go @@ -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 +} diff --git a/pkg/migrations/mysql/20220531013542_margin_interests.go b/pkg/migrations/mysql/20220531013542_margin_interests.go new file mode 100644 index 000000000..b6f3be151 --- /dev/null +++ b/pkg/migrations/mysql/20220531013542_margin_interests.go @@ -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 +} diff --git a/pkg/migrations/mysql/20220531015005_margin_liquidations.go b/pkg/migrations/mysql/20220531015005_margin_liquidations.go new file mode 100644 index 000000000..194c0a67f --- /dev/null +++ b/pkg/migrations/mysql/20220531015005_margin_liquidations.go @@ -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 +} diff --git a/pkg/migrations/sqlite3/20220531012226_margin_loans.go b/pkg/migrations/sqlite3/20220531012226_margin_loans.go new file mode 100644 index 000000000..25bfc68b9 --- /dev/null +++ b/pkg/migrations/sqlite3/20220531012226_margin_loans.go @@ -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 +} diff --git a/pkg/migrations/sqlite3/20220531013327_margin_repays.go b/pkg/migrations/sqlite3/20220531013327_margin_repays.go new file mode 100644 index 000000000..d91564322 --- /dev/null +++ b/pkg/migrations/sqlite3/20220531013327_margin_repays.go @@ -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 +} diff --git a/pkg/migrations/sqlite3/20220531013541_margin_interests.go b/pkg/migrations/sqlite3/20220531013541_margin_interests.go new file mode 100644 index 000000000..0c06a2ce6 --- /dev/null +++ b/pkg/migrations/sqlite3/20220531013541_margin_interests.go @@ -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 +} diff --git a/pkg/migrations/sqlite3/20220531015005_margin_liquidations.go b/pkg/migrations/sqlite3/20220531015005_margin_liquidations.go new file mode 100644 index 000000000..5f1e07f76 --- /dev/null +++ b/pkg/migrations/sqlite3/20220531015005_margin_liquidations.go @@ -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 +}