Skip to content

Commit

Permalink
compile and update migration package
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 31, 2022
1 parent 79fbad1 commit 7601f08
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/migrations/mysql/20220531012226_margin_loans.go
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
}
34 changes: 34 additions & 0 deletions pkg/migrations/mysql/20220531013327_margin_repays.go
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
}
34 changes: 34 additions & 0 deletions pkg/migrations/mysql/20220531013542_margin_interests.go
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 pkg/migrations/mysql/20220531015005_margin_liquidations.go
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
}
34 changes: 34 additions & 0 deletions pkg/migrations/sqlite3/20220531012226_margin_loans.go
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
}
34 changes: 34 additions & 0 deletions pkg/migrations/sqlite3/20220531013327_margin_repays.go
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
}
34 changes: 34 additions & 0 deletions pkg/migrations/sqlite3/20220531013541_margin_interests.go
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 pkg/migrations/sqlite3/20220531015005_margin_liquidations.go
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
}

0 comments on commit 7601f08

Please sign in to comment.