Initial commit

This commit is contained in:
Yaser
2026-08-13 19:50:53 +03:30
commit 38084458fe
879 changed files with 95198 additions and 0 deletions

80
db/influxdb.sql Normal file
View File

@@ -0,0 +1,80 @@
CREATE DATABASE peatio_development;
CREATE DATABASE peatio_test;
CREATE CONTINUOUS QUERY "trade_to_cq_1m" ON peatio_development
RESAMPLE EVERY 1s FOR 3m
BEGIN
SELECT FIRST(price) AS open, max(price) AS high, min(price) AS low, last(price) AS close, sum(amount) AS volume INTO candles_1m FROM trades GROUP BY time(1m), market
END;
CREATE CONTINUOUS QUERY "candles_1m_to_cq_1m" ON peatio_development
RESAMPLE EVERY 1m FOR 2m
BEGIN
SELECT last(close) AS open, last(close) AS high, last(close) AS low, last(close) AS close, last(volume) * 0 as volume INTO candles_1m FROM candles_1m GROUP BY time(1m), market fill(previous)
END;
CREATE CONTINUOUS QUERY "cq_5m" ON peatio_development
RESAMPLE EVERY 5s FOR 10m
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_5m" FROM "candles_1m" GROUP BY time(5m), market
END;
CREATE CONTINUOUS QUERY "cq_15m" ON peatio_development
RESAMPLE EVERY 5s FOR 30m
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_15m" FROM "candles_5m" GROUP BY time(15m), market
END;
CREATE CONTINUOUS QUERY "cq_30m" ON peatio_development
RESAMPLE EVERY 5s FOR 1h
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_30m" FROM "candles_15m" GROUP BY time(30m), market
END;
CREATE CONTINUOUS QUERY "cq_1h" ON peatio_development
RESAMPLE EVERY 5s FOR 2h
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_1h" FROM "candles_30m" GROUP BY time(1h), market
END;
CREATE CONTINUOUS QUERY "cq_2h" ON peatio_development
RESAMPLE EVERY 5s FOR 4h
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_2h" FROM "candles_1h" GROUP BY time(2h), market
END;
CREATE CONTINUOUS QUERY "cq_4h" ON peatio_development
RESAMPLE EVERY 5s FOR 8h
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_4h" FROM "candles_2h" GROUP BY time(4h), market
END;
CREATE CONTINUOUS QUERY "cq_6h" ON peatio_development
RESAMPLE EVERY 5s FOR 12h
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_6h" FROM "candles_2h" GROUP BY time(6h), market
END;
CREATE CONTINUOUS QUERY "cq_12h" ON peatio_development
RESAMPLE EVERY 5s FOR 24h
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_12h" FROM "candles_6h" GROUP BY time(12h), market
END;
CREATE CONTINUOUS QUERY "cq_1d" ON peatio_development
RESAMPLE EVERY 5s FOR 2d
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_1d" FROM "candles_6h" GROUP BY time(1d), market
END;
CREATE CONTINUOUS QUERY "cq_3d" ON peatio_development
RESAMPLE EVERY 5s FOR 6d
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_3d" FROM "candles_1d" GROUP BY time(3d), market
END;
CREATE CONTINUOUS QUERY "cq_1w" ON peatio_development
RESAMPLE EVERY 5s FOR 2w
BEGIN
SELECT FIRST(open) as open, MAX(high) as high, MIN(low) as low, LAST(close) as close, SUM(volume) as volume INTO "candles_1w" FROM "candles_1d" GROUP BY time(7d), market
END;

View File

@@ -0,0 +1,253 @@
# encoding: UTF-8
# frozen_string_literal: true
class InitSchema < ActiveRecord::Migration[4.2]
def up
create_table "account_versions", force: :cascade do |t|
t.integer "member_id", limit: 4
t.integer "account_id", limit: 4
t.integer "reason", limit: 4
t.decimal "balance", precision: 32, scale: 16
t.decimal "locked", precision: 32, scale: 16
t.decimal "fee", precision: 32, scale: 16
t.decimal "amount", precision: 32, scale: 16
t.integer "modifiable_id", limit: 4
t.string "modifiable_type", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.integer "currency", limit: 4
t.integer "fun", limit: 4
end
add_index "account_versions", ["account_id", "reason"], name: "index_account_versions_on_account_id_and_reason", using: :btree
add_index "account_versions", ["account_id"], name: "index_account_versions_on_account_id", using: :btree
add_index "account_versions", ["member_id", "reason"], name: "index_account_versions_on_member_id_and_reason", using: :btree
add_index "account_versions", ["modifiable_id", "modifiable_type"], name: "index_account_versions_on_modifiable_id_and_modifiable_type", using: :btree
create_table "accounts", force: :cascade do |t|
t.integer "member_id", limit: 4
t.integer "currency", limit: 4
t.decimal "balance", precision: 32, scale: 16
t.decimal "locked", precision: 32, scale: 16
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "in", precision: 32, scale: 16
t.decimal "out", precision: 32, scale: 16
t.integer "default_withdraw_fund_source_id", limit: 4
end
add_index "accounts", ["member_id", "currency"], name: "index_accounts_on_member_id_and_currency", using: :btree
add_index "accounts", ["member_id"], name: "index_accounts_on_member_id", using: :btree
create_table "api_tokens", force: :cascade do |t|
t.integer "member_id", limit: 4, null: false
t.string "access_key", limit: 50, null: false
t.string "secret_key", limit: 50, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "trusted_ip_list", limit: 255
t.string "label", limit: 255
t.datetime "expires_at"
t.string "scopes", limit: 255
t.datetime "deleted_at"
end
add_index "api_tokens", ["access_key"], name: "index_api_tokens_on_access_key", unique: true, using: :btree
add_index "api_tokens", ["secret_key"], name: "index_api_tokens_on_secret_key", unique: true, using: :btree
create_table "assets", force: :cascade do |t|
t.string "type", limit: 255
t.integer "attachable_id", limit: 4
t.string "attachable_type", limit: 255
t.string "file", limit: 255
end
create_table "audit_logs", force: :cascade do |t|
t.string "type", limit: 255
t.integer "operator_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.integer "auditable_id", limit: 4
t.string "auditable_type", limit: 255
t.string "source_state", limit: 255
t.string "target_state", limit: 255
end
add_index "audit_logs", ["auditable_id", "auditable_type"], name: "index_audit_logs_on_auditable_id_and_auditable_type", using: :btree
add_index "audit_logs", ["operator_id"], name: "index_audit_logs_on_operator_id", using: :btree
create_table "authentications", force: :cascade do |t|
t.string "provider", limit: 255
t.string "uid", limit: 255
t.string "secret", limit: 255
t.integer "member_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.string "nickname", limit: 255
end
add_index "authentications", ["member_id"], name: "index_authentications_on_member_id", using: :btree
add_index "authentications", ["provider", "uid"], name: "index_authentications_on_provider_and_uid", using: :btree
create_table "deposits", force: :cascade do |t|
t.integer "account_id", limit: 4
t.integer "member_id", limit: 4
t.integer "currency", limit: 4
t.decimal "amount", precision: 32, scale: 16
t.decimal "fee", precision: 32, scale: 16
t.string "fund_uid", limit: 255
t.string "fund_extra", limit: 255
t.string "txid", limit: 255
t.integer "state", limit: 4
t.string "aasm_state", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "done_at"
t.string "confirmations", limit: 255
t.string "type", limit: 255
t.integer "payment_transaction_id", limit: 4
t.integer "txout", limit: 4
end
add_index "deposits", ["txid", "txout"], name: "index_deposits_on_txid_and_txout", using: :btree
create_table "fund_sources", force: :cascade do |t|
t.integer "member_id", limit: 4
t.integer "currency", limit: 4
t.string "extra", limit: 255
t.string "uid", limit: 255
t.boolean "is_locked", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "deleted_at"
end
create_table "id_documents", force: :cascade do |t|
t.integer "id_document_type", limit: 4
t.string "name", limit: 255
t.string "id_document_number", limit: 255
t.integer "member_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.date "birth_date"
t.text "address", limit: 65535
t.string "city", limit: 255
t.string "country", limit: 255
t.string "zipcode", limit: 255
t.integer "id_bill_type", limit: 4
t.string "aasm_state", limit: 255
end
create_table "members", force: :cascade do |t|
t.string "sn", limit: 255
t.string "email", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "disabled", default: false
t.boolean "api_disabled", default: false
t.string "nickname", limit: 255
end
create_table "orders", force: :cascade do |t|
t.integer "bid", limit: 4
t.integer "ask", limit: 4
t.integer "currency", limit: 4
t.decimal "price", precision: 32, scale: 16
t.decimal "volume", precision: 32, scale: 16
t.decimal "origin_volume", precision: 32, scale: 16
t.integer "state", limit: 4
t.datetime "done_at"
t.string "type", limit: 8
t.integer "member_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.string "sn", limit: 255
t.string "source", limit: 255, null: false
t.string "ord_type", limit: 10
t.decimal "locked", precision: 32, scale: 16
t.decimal "origin_locked", precision: 32, scale: 16
t.decimal "funds_received", precision: 32, scale: 16, default: 0.0
t.integer "trades_count", limit: 4, default: 0
end
add_index "orders", ["currency", "state"], name: "index_orders_on_currency_and_state", using: :btree
add_index "orders", ["member_id", "state"], name: "index_orders_on_member_id_and_state", using: :btree
add_index "orders", ["member_id"], name: "index_orders_on_member_id", using: :btree
add_index "orders", ["state"], name: "index_orders_on_state", using: :btree
create_table "partial_trees", force: :cascade do |t|
t.integer "proof_id", limit: 4, null: false
t.integer "account_id", limit: 4, null: false
t.text "json", limit: 65535, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "sum", limit: 255
end
create_table "payment_addresses", force: :cascade do |t|
t.integer "account_id", limit: 4
t.string "address", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.integer "currency", limit: 4
t.string "secret", limit: 255
end
create_table "payment_transactions", force: :cascade do |t|
t.string "txid", limit: 255
t.decimal "amount", precision: 32, scale: 16
t.integer "confirmations", limit: 4
t.string "address", limit: 255
t.integer "state", limit: 4
t.string "aasm_state", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "receive_at"
t.datetime "dont_at"
t.integer "currency", limit: 4
t.string "type", limit: 60
t.integer "txout", limit: 4
end
add_index "payment_transactions", ["txid", "txout"], name: "index_payment_transactions_on_txid_and_txout", using: :btree
add_index "payment_transactions", ["type"], name: "index_payment_transactions_on_type", using: :btree
create_table "proofs", force: :cascade do |t|
t.string "root", limit: 255
t.integer "currency", limit: 4
t.boolean "ready", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "sum", limit: 255
t.text "addresses", limit: 65535
t.string "balance", limit: 30
end
create_table "trades", force: :cascade do |t|
t.decimal "price", precision: 32, scale: 16
t.decimal "volume", precision: 32, scale: 16
t.integer "ask_id", limit: 4
t.integer "bid_id", limit: 4
t.integer "trend", limit: 4
t.integer "currency", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.integer "ask_member_id", limit: 4
t.integer "bid_member_id", limit: 4
t.decimal "funds", precision: 32, scale: 16
end
add_index "trades", ["ask_id"], name: "index_trades_on_ask_id", using: :btree
add_index "trades", ["ask_member_id"], name: "index_trades_on_ask_member_id", using: :btree
add_index "trades", ["bid_id"], name: "index_trades_on_bid_id", using: :btree
add_index "trades", ["bid_member_id"], name: "index_trades_on_bid_member_id", using: :btree
add_index "trades", ["created_at"], name: "index_trades_on_created_at", using: :btree
add_index "trades", ["currency"], name: "index_trades_on_currency", using: :btree
create_table "versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", limit: 4, null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object", limit: 65535
t.datetime "created_at"
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
create_table "withdraws", force: :cascade do |t|
t.string "sn", limit: 255
t.integer "account_id", limit: 4
t.integer "member_id", limit: 4
t.integer "currency", limit: 4
t.decimal "amount", precision: 32, scale: 16
t.decimal "fee", precision: 32, scale: 16
t.string "fund_uid", limit: 255
t.string "fund_extra", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "done_at"
t.string "txid", limit: 255
t.string "aasm_state", limit: 255
t.decimal "sum", precision: 32, scale: 16, default: 0.0, null: false
t.string "type", limit: 255
end
end
def down
raise ActiveRecord::IrreversibleMigration, "The initial migration is not revertable"
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class RemoveKnowYourCustomer < ActiveRecord::Migration[4.2]
def change
drop_table :id_documents
end
end

View File

@@ -0,0 +1,16 @@
# encoding: UTF-8
# frozen_string_literal: true
class RefactorMemberStructure < ActiveRecord::Migration[4.2]
def change
change_column :members, :created_at, :datetime, null: false, after: :nickname
change_column :members, :updated_at, :datetime, null: false, after: :created_at
change_column :members, :sn, :string, null: false, limit: 14, index: true
change_column :members, :email, :string, null: false, index: true
change_column :members, :disabled, :boolean, null: false, default: false
change_column :members, :api_disabled, :boolean, null: false, default: false
change_column :members, :nickname, :string, null: true, limit: 32
add_column :members, :name, :string, null: true, limit: 45, after: :api_disabled
add_column :members, :level, :string, null: true, limit: 20, after: :id, default: ''
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class DropAssets < ActiveRecord::Migration[4.2]
def change
drop_table :assets
end
end

View File

@@ -0,0 +1,17 @@
# encoding: UTF-8
# frozen_string_literal: true
class ShortenMemberSerialNumber < ActiveRecord::Migration[4.2]
def change
if defined?(Member)
Member.find_each do |member|
if member.sn.length > 12
member.sn = nil
member.send(:assign_sn)
member.save!
end
end
end
change_column :members, :sn, :string, null: false, limit: 12, index: true
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class MakeSerialNumberUnique < ActiveRecord::Migration[4.2]
def change
remove_index :members, :sn if index_exists?(:members, :sn)
add_index :members, :sn, unique: true
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class RefactorAuthenticationToken < ActiveRecord::Migration[4.2]
def change
change_column :authentications, :secret, :text
rename_column :authentications, :secret, :token
end
end

View File

@@ -0,0 +1,19 @@
# encoding: UTF-8
# frozen_string_literal: true
class AddCurrencies < ActiveRecord::Migration[4.2]
def change
create_table :currencies do |t|
t.string :key, limit: 30, null: false
t.string :code, limit: 30, null: false, index: { unique: true }
t.string :symbol, limit: 1, null: false
t.string :type, limit: 30, null: false, default: 'coin'
t.decimal :quick_withdraw_limit, precision: 32, scale: 16, null: false, default: 0
t.string :options, limit: 1000, default: '{}', null: false
t.boolean :visible, default: true, null: false, index: true
t.integer :base_factor, default: 1, null: false, limit: 8
t.integer :precision, limit: 1, default: 8, null: false
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,10 @@
# encoding: UTF-8
# frozen_string_literal: true
class RemoveNameAndNickname < ActiveRecord::Migration[4.2]
def change
remove_column :members, :nickname if column_exists?(:members, :nickname)
remove_column :members, :name if column_exists?(:members, :name)
remove_column :authentications, :nickname if column_exists?(:authentications, :nickname)
end
end

View File

@@ -0,0 +1,12 @@
# encoding: UTF-8
# frozen_string_literal: true
class GoodCurrencyForeignKey < ActiveRecord::Migration[4.2]
def change
%i[ account_versions accounts deposits fund_sources payment_addresses payment_transactions proofs withdraws ].each do |t|
remove_index t, :currency if index_exists?(t, :currency)
rename_column t, :currency, :currency_id
add_index t, :currency_id
end
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class AddDetailsToPaymentAddresses < ActiveRecord::Migration[4.2]
def change
add_column :payment_addresses, :details, :string, limit: 1.kilobyte, null: false, default: '{}'
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class DropAPITokens < ActiveRecord::Migration[4.2]
def change
drop_table :api_tokens
end
end

View File

@@ -0,0 +1,48 @@
# encoding: UTF-8
# frozen_string_literal: true
class CreateWithdrawDestinationsDropFundSource < ActiveRecord::Migration[4.2]
def change
create_table :withdraw_destinations do |t|
t.string :type, null: false, limit: 30, index: true
t.integer :member_id, null: false, index: true
t.integer :currency_id, null: false, index: true
t.string :details, limit: 4.kilobytes, null: false, default: '{}'
t.timestamps null: false
end
add_column :withdraws, :destination_id, :integer, after: :id, null: true, index: true
migrate_existing_data
remove_column :withdraws, :fund_uid
remove_column :withdraws, :fund_extra
rename_column :accounts, :default_withdraw_fund_source_id, :default_withdraw_destination_id
drop_table :fund_sources
end
private
def migrate_existing_data
return unless defined?(Withdraw) && defined?(WithdrawDestination)
Withdraw.transaction do
Withdraw.find_each do |withdraw|
if Withdraws::Fiat === withdraw
WithdrawDestination::Fiat.create! \
label: withdraw.fund_extra,
member: withdraw.member,
currency: withdraw.currency,
bank_name: withdraw.fund_extra,
bank_account_number: withdraw.fund_uid
else
WithdrawDestination::Coin.create! \
label: withdraw.fund_extra,
member: withdraw.member,
currency: withdraw.currency,
address: withdraw.fund_uid
end.tap { |record| withdraw.update!(destination: record) }
end
end
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class MigrateAllCurrencyModelsToSingle < ActiveRecord::Migration[4.2]
def change
execute %[ UPDATE deposits SET type = 'Deposits::Coin' WHERE type <> 'Deposits::Bank' ]
execute %[ UPDATE withdraws SET type = 'Withdraws::Coin' WHERE type <> 'Withdraws::Bank' ]
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class RemoveInAndOut < ActiveRecord::Migration[4.2]
def change
remove_columns :accounts, :in, :out
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class MigrateAllBankModelsToFiat < ActiveRecord::Migration[4.2]
def change
execute %[ UPDATE deposits SET type = 'Deposits::Fiat' WHERE type = 'Deposits::Bank' ]
execute %[ UPDATE withdraws SET type = 'Withdraws::Fiat' WHERE type = 'Withdraws::Bank' ]
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class RemoveKeyFromCurrency < ActiveRecord::Migration[4.2]
def change
remove_column :currencies, :key
end
end

View File

@@ -0,0 +1,22 @@
# encoding: UTF-8
# frozen_string_literal: true
class CreateMarkets < ActiveRecord::Migration[4.2]
def change
create_table :markets do |t|
t.string :ask_unit, null: false, limit: 5, index: true
t.string :bid_unit, null: false, limit: 5, index: true
t.decimal :ask_fee, null: false, default: 0, precision: 7, scale: 6
t.decimal :bid_fee, null: false, default: 0, precision: 7, scale: 6
t.integer :ask_precision, null: false, limit: 1, default: 4
t.integer :bid_precision, null: false, limit: 1, default: 4
t.integer :position, null: false, default: 0, index: true
t.boolean :visible, null: false, default: true, index: true
t.timestamps null: false
end
change_column :markets, :id, :string, limit: 10
add_index :markets, %i[ ask_unit bid_unit ], unique: true
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class AlterCurrency < ActiveRecord::Migration[4.2]
def change
change_column :orders, :currency, :string, limit: 10
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class AlterTradesCurrency < ActiveRecord::Migration[4.2]
def change
change_column :trades, :currency, :string, limit: 10
rename_column :trades, :currency, :market_id
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class AlterOrdersCurrency < ActiveRecord::Migration[4.2]
def change
rename_column :orders, :currency, :market_id
end
end

View File

@@ -0,0 +1,14 @@
# encoding: UTF-8
# frozen_string_literal: true
class UpdateDeprecatedCurrencyIds < ActiveRecord::Migration[4.2]
def change
# Migrate deprecated market codes to new.
if File.file?('config/markets.old.yml')
(YAML.load_file('config/markets.old.yml') || []).each do |market|
execute %{UPDATE orders SET market_id = '#{market.fetch('id')}' WHERE market_id = '#{market.fetch('code')}'}
execute %{UPDATE trades SET market_id = '#{market.fetch('id')}' WHERE market_id = '#{market.fetch('code')}'}
end
end
end
end

View File

@@ -0,0 +1,10 @@
# encoding: UTF-8
# frozen_string_literal: true
class AddTIDToDeposit < ActiveRecord::Migration[4.2]
def change
add_column :deposits, :tid, :string, limit: 64
execute %{UPDATE deposits SET tid = CONCAT('TID', id, currency_id, member_id) WHERE tid IS NULL}
change_column :deposits, :tid, :string, null: false, index: { unique: true }, limit: 64
end
end

View File

@@ -0,0 +1,10 @@
# encoding: UTF-8
# frozen_string_literal: true
class AddTIDToWithdraw < ActiveRecord::Migration[4.2]
def change
add_column :withdraws, :tid, :string, limit: 64
execute %{UPDATE withdraws SET tid = CONCAT('TID', id, currency_id, member_id) WHERE tid IS NULL}
change_column :withdraws, :tid, :string, null: false, index: { unique: true }, limit: 64
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class AddBidToWithdraws < ActiveRecord::Migration[4.2]
def change
add_column :withdraws, :bid, :string, limit: 64
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class ChangeBidToRid < ActiveRecord::Migration[4.2]
def change
rename_column :withdraws, :bid, :rid
end
end

View File

@@ -0,0 +1,14 @@
# encoding: UTF-8
# frozen_string_literal: true
class MigrateStates < ActiveRecord::Migration[4.2]
def change
execute %{UPDATE deposits SET aasm_state = 'submitted' WHERE aasm_state = 'submitting'}
execute %{UPDATE deposits SET aasm_state = 'accepted' WHERE aasm_state = 'checked' OR aasm_state = 'warning'}
execute %{UPDATE deposits SET aasm_state = 'canceled' WHERE aasm_state = 'cancelled'}
execute %{UPDATE withdraws SET aasm_state = 'prepared' WHERE aasm_state = 'submitting'}
execute %{UPDATE withdraws SET aasm_state = 'suspected' WHERE aasm_state = 'suspect'}
execute %{UPDATE withdraws SET aasm_state = 'succeed' WHERE aasm_state = 'done'}
execute %{UPDATE withdraws SET aasm_state = 'canceled' WHERE aasm_state = 'cancelled'}
end
end

View File

@@ -0,0 +1,25 @@
# encoding: UTF-8
# frozen_string_literal: true
class DropWithdrawDestinations < ActiveRecord::Migration[4.2]
class WithdrawDestination < ActiveRecord::Base
serialize :details, JSON
self.inheritance_column = :disabled
end
def change
execute('SELECT id, type, destination_id FROM withdraws').each do |fields|
record = WithdrawDestination.where(type: fields[1].gsub(/Withdraws::/, 'WithdrawDestination::'))
.find_by_id(fields[2])
rid = if record
fields[1].match?(/fiat/) ? record.details['bank_account_number'] : record.details['address']
end.presence || fields[0]
execute "UPDATE withdraws SET rid = #{connection.quote(rid)} WHERE id = #{connection.quote(fields[0])}"
end
remove_column :withdraws, :destination_id
drop_table :withdraw_destinations
change_column :withdraws, :rid, :string, limit: 64, null: false
remove_column :accounts, :default_withdraw_destination_id
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class RemoveSnFromWithdraw < ActiveRecord::Migration[4.2]
def change
remove_column :withdraws, :sn
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class RemoveFundUidExtraFromDeposit < ActiveRecord::Migration[4.2]
def change
remove_column :deposits, :fund_uid
remove_column :deposits, :fund_extra
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class DropUselessDepositState < ActiveRecord::Migration[4.2]
def change
remove_column :deposits, :state
end
end

View File

@@ -0,0 +1,33 @@
# encoding: UTF-8
# frozen_string_literal: true
class RefactorDeposit < ActiveRecord::Migration[4.2]
def change
change_column_null :deposits, :account_id, false
change_column_null :deposits, :member_id, false
change_column_null :deposits, :currency_id, false
change_column_null :deposits, :amount, false
change_column_null :deposits, :fee, false
change_column_null :deposits, :aasm_state, false
change_column_null :deposits, :created_at, false
change_column_null :deposits, :updated_at, false
add_column :deposits, :new_confirmations, :integer, null: false, default: 0, after: :confirmations
Deposit.where('confirmations IS NOT NULL').update_all(new_confirmations: 'confirmations')
remove_column :deposits, :confirmations
rename_column :deposits, :new_confirmations, :confirmations
change_column :deposits, :type, :string, null: false, limit: 30
add_index :deposits, :type
change_column :deposits, :txid, :string, null: true, limit: 128
change_column :deposits, :created_at, :datetime, null: false, after: :tid
change_column :deposits, :updated_at, :datetime, null: false, after: :created_at
change_column :deposits, :done_at, :datetime, after: :updated_at
remove_column :deposits, :account_id
change_column :deposits, :txout, :integer, after: :txid
remove_index :deposits, column: %i[txid txout]
add_column :deposits, :address, :string, after: :fee, index: true, limit: 64
add_index :deposits, %i[currency_id txid txout], unique: true
remove_column :deposits, :payment_transaction_id
rename_column :deposits, :done_at, :completed_at
drop_table :payment_transactions
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class AddFeeToOrders < ActiveRecord::Migration[4.2]
def change
add_column :orders, :fee, :decimal, null: false, default: 0, precision: 7, scale: 6, after: :origin_volume
end
end

View File

@@ -0,0 +1,15 @@
# encoding: UTF-8
# frozen_string_literal: true
class MigrateDepositChannelsToCurrency < ActiveRecord::Migration[4.2]
def change
if defined?(Currency) && File.file?('config/deposit_channels.old.yml')
(YAML.load_file('config/deposit_channels.old.yml') || []).each do |channel|
next unless channel.key?('min_confirm')
Currency.find(channel.fetch('currency')).tap do |ccy|
ccy.update_columns(options: ccy.options.reverse_merge(deposit_confirmations: channel['min_confirm']))
end
end
end
end
end

View File

@@ -0,0 +1,15 @@
# encoding: UTF-8
# frozen_string_literal: true
class MigrateWithdrawChannelsToCurrency < ActiveRecord::Migration[4.2]
def change
add_column :currencies, :withdraw_fee, :decimal, after: :quick_withdraw_limit, null: false, default: 0, precision: 7, scale: 6
if defined?(Currency) && File.file?('config/withdraw_channels.old.yml')
(YAML.load_file('config/withdraw_channels.old.yml') || []).each do |channel|
Currency.find(channel.fetch('currency')).tap do |ccy|
ccy.update_columns(withdraw_fee: channel.fetch('fee'))
end
end
end
end
end

View File

@@ -0,0 +1,11 @@
# encoding: UTF-8
# frozen_string_literal: true
class IncreaseFeeLimits < ActiveRecord::Migration[4.2]
def change
change_column :markets, :ask_fee, :decimal, null: false, default: 0, precision: 32, scale: 16
change_column :markets, :bid_fee, :decimal, null: false, default: 0, precision: 32, scale: 16
change_column :orders, :fee, :decimal, null: false, default: 0, precision: 32, scale: 16
change_column :currencies, :withdraw_fee, :decimal, null: false, default: 0, precision: 32, scale: 16
end
end

View File

@@ -0,0 +1,8 @@
# encoding: UTF-8
# frozen_string_literal: true
class AddDepositFeeToCurrencies < ActiveRecord::Migration[4.2]
def change
add_column :currencies, :deposit_fee, :decimal, after: :type, null: false, default: 0, precision: 32, scale: 16
end
end

View File

@@ -0,0 +1,11 @@
# encoding: UTF-8
# frozen_string_literal: true
class LimitTradingFee < ActiveRecord::Migration[4.2]
def change
execute %{UPDATE markets SET ask_fee = 0.5 WHERE ask_fee > 0.5}
execute %{UPDATE markets SET bid_fee = 0.5 WHERE bid_fee > 0.5}
change_column :markets, :ask_fee, :decimal, null: false, default: 0, precision: 17, scale: 16
change_column :markets, :bid_fee, :decimal, null: false, default: 0, precision: 17, scale: 16
end
end

View File

@@ -0,0 +1,22 @@
# encoding: UTF-8
# frozen_string_literal: true
class ConvertToLegacyBitcoinCashAddresses < ActiveRecord::Migration[4.2]
def change
return unless defined?(PaymentAddress)
return unless defined?(Currency)
return unless table_exists?(:payment_addresses)
return unless column_exists?(:payment_addresses, :address)
return unless column_exists?(:payment_addresses, :currency_id)
return unless column_exists?(:currencies, :id)
return unless column_exists?(:currencies, :code)
Currency.find_by_id(:bch).tap do |ccy|
break unless ccy
PaymentAddress.where(currency: ccy).find_each do |pa|
next if pa.address.blank?
pa.update_columns(address: CashAddr::Converter.to_legacy_address(pa.address))
end
end
end
end

View File

@@ -0,0 +1,18 @@
# encoding: UTF-8
# frozen_string_literal: true
class ChangeWalletIdToAddressId < ActiveRecord::Migration[4.2]
def change
return unless defined?(PaymentAddress)
return unless column_exists?(:payment_addresses, :details)
PaymentAddress.find_each do |pa|
pa.details['wallet_id'].tap do |wallet_id|
if wallet_id
pa.details['bitgo_address_id'] = wallet_id
pa.details.delete('wallet_id')
pa.update_column(:details, pa.details)
end
end
end
end
end

View File

@@ -0,0 +1,26 @@
# encoding: UTF-8
# frozen_string_literal: true
class NormalizeAddressesAndTransactions < ActiveRecord::Migration[4.2]
class Ccy < ActiveRecord::Base
serialize :options, JSON
self.table_name = 'currencies'
self.inheritance_column = :disabled
end
def change
Ccy.where(type: :coin).find_each do |ccy|
if ccy.code.in?(%w[eth ethd])
ccy.options['bitgo_wallet_address'].try(:downcase!)
ccy.options['erc20_contract_address'].try(:downcase!)
ccy.save
execute %[UPDATE deposits SET address = LOWER(address), txid = LOWER(txid) WHERE currency_id = #{ccy.id}]
execute %[UPDATE payment_addresses SET address = LOWER(address) WHERE currency_id = #{ccy.id}]
execute %[UPDATE withdraws SET rid = LOWER(rid), txid = LOWER(txid) WHERE type = 'Withdraws::Coin' AND currency_id = #{ccy.id}]
else
ccy.options['case_sensitive'] = true
ccy.save
end
end
end
end

View File

@@ -0,0 +1,29 @@
# encoding: UTF-8
# frozen_string_literal: true
class CaseSensitiveData < ActiveRecord::Migration[4.2]
def change
case ActiveRecord::Base.connection.adapter_name
when 'Mysql2'
execute %[ALTER TABLE deposits MODIFY address VARCHAR(64) BINARY;]
execute %[ALTER TABLE deposits MODIFY txid VARCHAR(128) BINARY;]
execute %[ALTER TABLE deposits MODIFY tid VARCHAR(64) BINARY NOT NULL;]
execute %[ALTER TABLE withdraws MODIFY txid VARCHAR(128) BINARY;]
execute %[ALTER TABLE payment_addresses MODIFY address VARCHAR(64) BINARY;]
execute %[ALTER TABLE withdraws MODIFY tid VARCHAR(64) BINARY NOT NULL;]
execute %[ALTER TABLE withdraws MODIFY rid VARCHAR(64) BINARY NOT NULL;]
when 'PostgreSQL'
enable_extension 'citext'
change_column :deposits, :address, :citext
change_column :deposits, :txid, :citext
change_column :deposits, :tid, :citext, null: false
change_column :withdraws, :txid, :citext
change_column :payment_addresses, :address, :citext
change_column :withdraws, :tid, :citext, null: false
change_column :withdraws, :rid, :citext, null: false
else
raise "Unsupported adapter: #{ActiveRecord::Base.connection.adapter_name}"
end
end
end

View File

@@ -0,0 +1,14 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImprovePaymentAddressModel < ActiveRecord::Migration[4.2]
def change
change_column :payment_addresses, :created_at, :datetime, null: false, after: :details
change_column :payment_addresses, :updated_at, :datetime, null: false, after: :created_at
change_column :payment_addresses, :secret, :string, null: true, limit: 128
change_column :payment_addresses, :account_id, :integer, null: false
change_column :payment_addresses, :currency_id, :integer, null: false, after: :id
add_index :payment_addresses, :account_id, unique: true
add_index :payment_addresses, [:currency_id, :address], unique: true
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveMemberModel < ActiveRecord::Migration[4.2]
def change
add_index :members, :email, unique: true
add_index :members, :disabled
end
end

View File

@@ -0,0 +1,15 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveAuditModel < ActiveRecord::Migration[4.2]
def change
change_column :audit_logs, :type, :string, limit: 30, null: false
change_column :audit_logs, :operator_id, :integer, null: true
change_column :audit_logs, :created_at, :datetime, after: :target_state, null: false
change_column :audit_logs, :updated_at, :datetime, after: :created_at, null: false
change_column :audit_logs, :auditable_type, :string, limit: 30, null: false
change_column :audit_logs, :auditable_id, :integer, null: false
change_column :audit_logs, :target_state, :string, null: false, limit: 30
change_column :audit_logs, :source_state, :string, null: true, limit: 30
end
end

View File

@@ -0,0 +1,16 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveAuthModel < ActiveRecord::Migration[4.2]
def change
change_column :authentications, :provider, :string, null: false, limit: 30
change_column :authentications, :uid, :string, null: false, limit: 255
change_column :authentications, :token, :string, null: true, limit: 1024
change_column :authentications, :member_id, :integer, null: false
change_column :authentications, :created_at, :datetime, null: false
change_column :authentications, :updated_at, :datetime, null: false
remove_index :authentications, column: %i[provider uid]
add_index :authentications, %i[provider uid], unique: true
add_index :authentications, %i[provider member_id], unique: true
end
end

View File

@@ -0,0 +1,17 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveAccountModel < ActiveRecord::Migration[4.2]
def change
change_column :accounts, :member_id, :integer, null: false
change_column :accounts, :currency_id, :integer, null: false
change_column_null :accounts, :balance, false
change_column_null :accounts, :locked, false
change_column_null :accounts, :created_at, false
change_column_null :accounts, :updated_at, false
change_column_default :accounts, :balance, 0
change_column_default :accounts, :locked, 0
remove_index :accounts, column: %i[member_id currency_id]
add_index :accounts, %i[currency_id member_id], unique: true
end
end

View File

@@ -0,0 +1,29 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveOrderModel < ActiveRecord::Migration[4.2]
def change
remove_columns :orders, :sn, :done_at, :source
execute %[DELETE FROM orders WHERE ask IS NULL OR bid IS NULL]
change_column :orders, :bid, :integer, null: false
change_column :orders, :ask, :integer, null: false
change_column :orders, :market_id, :string, null: false, limit: 10
change_column_null :orders, :volume, false
change_column_null :orders, :origin_volume, false
change_column_null :orders, :state, false
change_column_null :orders, :type, false
change_column_null :orders, :member_id, false
change_column :orders, :created_at, :datetime, null: false, after: :trades_count
change_column :orders, :updated_at, :datetime, null: false, after: :created_at
change_column :orders, :ord_type, :string, null: false, limit: 30
change_column_null :orders, :locked, false
change_column_null :orders, :origin_locked, false
change_column_null :orders, :trades_count, false
change_column_default :orders, :locked, 0
change_column_default :orders, :origin_locked, 0
remove_index :orders, column: %i[market_id state]
remove_index :orders, column: %i[member_id state]
add_index :orders, %i[type state member_id]
add_index :orders, %i[type state market_id]
end
end

View File

@@ -0,0 +1,9 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveOrderModel2 < ActiveRecord::Migration[4.2]
def change
add_index :orders, %i[type market_id]
add_index :orders, %i[type member_id]
end
end

View File

@@ -0,0 +1,25 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveTradeModel < ActiveRecord::Migration[4.2]
def change
change_column_null :trades, :price, false
change_column_null :trades, :volume, false
change_column_null :trades, :ask_id, false
change_column_null :trades, :bid_id, false
change_column_null :trades, :trend, false
change_column_null :trades, :market_id, false
change_column_null :trades, :created_at, false
change_column_null :trades, :updated_at, false
change_column_null :trades, :ask_member_id, false
change_column_null :trades, :bid_member_id, false
change_column_null :trades, :funds, false
change_column :trades, :created_at, :datetime, after: :funds
change_column :trades, :updated_at, :datetime, after: :created_at
remove_index :trades, column: :ask_member_id
remove_index :trades, column: :bid_member_id
remove_index :trades, column: :created_at
add_index :trades, [:market_id, :created_at]
add_index :trades, [:ask_member_id, :bid_member_id]
end
end

View File

@@ -0,0 +1,5 @@
class CurrencyVisibleToEnabled < ActiveRecord::Migration[4.2]
def change
rename_column :currencies, :visible, :enabled
end
end

View File

@@ -0,0 +1,27 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveWithdrawModel < ActiveRecord::Migration[4.2]
def change
change_column_null :withdraws, :account_id, false
change_column_null :withdraws, :member_id, false
change_column_null :withdraws, :currency_id, false
change_column_null :withdraws, :amount, false
change_column_null :withdraws, :fee, false
change_column :withdraws, :created_at, :datetime, after: :rid, null: false
change_column :withdraws, :updated_at, :datetime, after: :created_at, null: false
change_column :withdraws, :done_at, :datetime, after: :updated_at
rename_column :withdraws, :done_at, :completed_at
change_column_null :withdraws, :aasm_state, false
change_column_null :withdraws, :type, false
change_column :withdraws, :type, :string, limit: 30, null: false
add_index :withdraws, :aasm_state
add_index :withdraws, :account_id
add_index :withdraws, :member_id
add_index :withdraws, :type
add_index :withdraws, :tid
add_index :withdraws, %i[currency_id txid], unique: true
change_column :withdraws, :aasm_state, :string, limit: 30, null: false
change_column_default :withdraws, :sum, nil
end
end

View File

@@ -0,0 +1,11 @@
# encoding: UTF-8
# frozen_string_literal: true
class ImproveDepositModel < ActiveRecord::Migration[4.2]
def change
change_column :deposits, :aasm_state, :string, limit: 30, null: false
add_index :deposits, %i[member_id txid]
add_index :deposits, %i[aasm_state member_id currency_id]
add_index :deposits, :tid
end
end

View File

@@ -0,0 +1,14 @@
class AddFieldSupportsCashAddrFormatToCurrencies < ActiveRecord::Migration[4.2]
class Ccy < ActiveRecord::Base
serialize :options, JSON
self.table_name = 'currencies'
self.inheritance_column = :disabled
end
def change
Ccy.where(type: :coin).find_each do |ccy|
ccy.update_columns \
options: ccy.options.merge('supports_cash_addr_format' => ccy.code.in?(%w[bch bchd]))
end
end
end

View File

@@ -0,0 +1,5 @@
class MarketVisibleToEnabled < ActiveRecord::Migration[4.2]
def change
rename_column :markets, :visible, :enabled
end
end

View File

@@ -0,0 +1,5 @@
class DropAccountVersions < ActiveRecord::Migration[4.2]
def change
drop_table :account_versions
end
end

View File

@@ -0,0 +1,8 @@
class ImproveIndexes < ActiveRecord::Migration[4.2]
def change
remove_index :trades, column: [:market_id]
remove_index :accounts, column: [:currency_id]
add_index :currencies, [:enabled, :code]
remove_index :currencies, column: [:enabled]
end
end

View File

@@ -0,0 +1,6 @@
class ImproveDefaultsForMarket < ActiveRecord::Migration[4.2]
def change
change_column_default :markets, :ask_precision, 8
change_column_default :markets, :bid_precision, 8
end
end

View File

@@ -0,0 +1,46 @@
# frozen_string_literal: true
class ReplaceIdToCode < ActiveRecord::Migration[4.2]
def up
ActiveRecord::Base.transaction do
change_column :currencies, :code, :string, limit: 10, null: false
change_column :currencies, :id, :string, limit: 10, null: false
change_column :deposits, :currency_id, :string, limit: 10
change_column :withdraws, :currency_id, :string, limit: 10
change_column :payment_addresses, :currency_id, :string, limit: 10
change_column :accounts, :currency_id, :string, limit: 10
change_column :proofs, :currency_id, :string, limit: 10
change_column :orders, :ask, :string, limit: 10
change_column :orders, :bid, :string, limit: 10
Currency.all.each do |c|
Deposits.where(currency_id: c.id).update_all(currency_id: c.code)
Withdraws.where(currency_id: c.id).update_all(currency_id: c.code)
PaymentAddresses.where(currency_id: c.id).update_all(currency_id: c.code)
Accounts.where(currency_id: c.id).update_all(currency_id: c.code)
Proofs.where(currency_id: c.id).update_all(currency_id: c.code)
%i[deposits withdraws payment_addresses accounts proofs].each do |t|
change_column t, :currency_id, :string, limit: 10
end
Orders.where(ask: c.id).update_all(ask: c.code)
Orders.where(bid: c.id).update_all(bid: c.code)
end
Currency.update_all('id = code')
remove_column :currencies, :code
if index_exists?(:currencies, %i[enabled code])
remove_index :currencies, column: %i[enabled code]
end
add_index :currencies, [:enabled]
end
end
def down
raise ActiveRecord::IrreversibleMigration, "This migration can't be rollbacked"
end
end

View File

@@ -0,0 +1,27 @@
# frozen_string_literal: true
class ChangeMembersLevelType < ActiveRecord::Migration[4.2]
def up
add_column :members, :level_int, :integer, default: 0, null: false, limit: 1
Member.where(level: nil).update_all(level_int: 0)
Member.where(level: '').update_all(level_int: 0)
Member.where(level: 'unverified').update_all(level_int: 0)
Member.where(level: 'email_verified').update_all(level_int: 1)
Member.where(level: 'phone_verified').update_all(level_int: 2)
Member.where(level: 'identity_verified').update_all(level_int: 3)
remove_column :members, :level
rename_column :members, :level_int, :level
end
def down
change_column :members, :level, :string, null: true, limit: 20
change_column_default :members, :level, ''
Member.where(level: 0).update_all(level: 'unverified')
Member.where(level: 1).update_all(level: 'email_verified')
Member.where(level: 2).update_all(level: 'phone_verified')
Member.where(level: 3).update_all(level: 'identity_verified')
end
end

View File

@@ -0,0 +1,5 @@
class AddMissingIndexForAuthentications < ActiveRecord::Migration[4.2]
def change
add_index :authentications, [:provider, :member_id, :uid], unique: true
end
end

View File

@@ -0,0 +1,27 @@
# encoding: UTF-8
# frozen_string_literal: true
class MultipleDepositAddresses < ActiveRecord::Migration[4.2]
class Currency < ActiveRecord::Base
serialize :options, JSON
self.inheritance_column = nil
end
def change
Currency.transaction do
Currency.where(type: :coin).find_each do |ccy|
unless ccy.options.key?('supports_hd_protocol')
ccy.options['supports_hd_protocol'] = \
ccy.id.in?(%w[btc btcd bch bchd ltc ltcd dash dashd]) ||
(ccy.id.in?(%w[xrp eth]) && ccy.options['api_client'] == 'BitGo')
end
unless ccy.options.key?('allow_multiple_deposit_addresses')
ccy.options['allow_multiple_deposit_addresses'] = false
end
ccy.save!
end
end
end
end

View File

@@ -0,0 +1,6 @@
class RemoveExtraIndexesFromPaymentAddresses < ActiveRecord::Migration[4.2]
def change
remove_index :payment_addresses, column: %i[account_id]
remove_index :payment_addresses, column: %i[currency_id]
end
end

View File

@@ -0,0 +1,6 @@
class RemoveSolvency < ActiveRecord::Migration[4.2]
def change
drop_table :partial_trees
drop_table :proofs
end
end

View File

@@ -0,0 +1,6 @@
class RemoveAuditing < ActiveRecord::Migration[4.2]
def change
drop_table :audit_logs
drop_table :versions
end
end

View File

@@ -0,0 +1,19 @@
class CreateBlockchains < ActiveRecord::Migration[4.2]
def change
create_table :blockchains do |t|
t.string :key, null: false, index: { unique: true }
t.string :name
t.string :client, null: false
t.string :server
t.integer :height, null: false
t.string :explorer_address
t.string :explorer_transaction
t.integer :min_confirmations, null: false, default: 6
t.string :status, null: false, index: true
t.timestamps null: false
end
add_column :currencies, :blockchain_key, :string, limit: 32, after: :id
end
end

View File

@@ -0,0 +1,15 @@
class CreateWallets < ActiveRecord::Migration[4.2]
def change
create_table :wallets do |t|
t.string :currency_id, limit: 5
t.string :name, limit: 64
t.string :address, null: false
t.string :kind, null: false, limit: 32
t.integer :nsig
t.integer :parent
t.string :status, null: true, limit: 32
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,5 @@
class AddConfirmationsToWithdraw < ActiveRecord::Migration[4.2]
def change
add_column :withdraws, :confirmations, :integer, limit: 4, default: 0, null: false, after: :rid
end
end

View File

@@ -0,0 +1,17 @@
class ReplaceDepositConfirmationsWithMinConfirmations < ActiveRecord::Migration[4.2]
class Currency < ActiveRecord::Base
serialize :options, JSON
self.table_name = 'currencies'
self.inheritance_column = :disabled
end
def change
currencies = YAML.load_file(Rails.root.join('config/seed/currencies.yml'))
Currency.where(type: :coin).find_each do |c|
currency_options = currencies.find { |el| el['id'] == c.id }['options']
min_confirmations = currency_options['min_confirmations'] || c.options['deposit_confirmations'].to_i
c.options.except!('deposit_confirmations').merge!(min_confirmations: min_confirmations)
c.save!
end
end
end

View File

@@ -0,0 +1,8 @@
class ReplaceConfirmatioinsCountWithBlockHeader < ActiveRecord::Migration[4.2]
def change
remove_column :deposits, :confirmations
remove_column :withdraws, :confirmations
add_column :deposits, :block_number, :integer, after: :aasm_state
add_column :withdraws, :block_number, :integer, after: :aasm_state
end
end

View File

@@ -0,0 +1,6 @@
class AddMinPriceToMarket < ActiveRecord::Migration[4.2]
def change
add_column :markets, :max_bid, :decimal, precision: 17, scale: 16, after: :bid_fee
add_column :markets, :min_ask, :decimal, null: false, default: 0, precision: 17, scale: 16, after: :max_bid
end
end

View File

@@ -0,0 +1,5 @@
class AddIconUrlToCurrency < ActiveRecord::Migration[4.2]
def change
add_column :currencies, :icon_url, :string, after: :precision, default: nil
end
end

View File

@@ -0,0 +1,6 @@
class AddMaxDepositAndGatewayToWallets < ActiveRecord::Migration[4.2]
def change
add_column :wallets, :gateway, :string, limit: 1000, default: '{}', null: false, after: :nsig
add_column :wallets, :max_balance, :decimal, default: 0, null: false, precision: 32, scale: 16, after: :gateway
end
end

View File

@@ -0,0 +1,5 @@
class AddBlockchainKeyToWallet < ActiveRecord::Migration[4.2]
def change
add_column :wallets, :blockchain_key, :string, limit: 32, after: :id
end
end

View File

@@ -0,0 +1,6 @@
class RemoveUrlsFromCurrencies < ActiveRecord::Migration[4.2]
def change
remove_column :currencies, :wallet_url_template, :string if column_exists? :currencies, :wallet_url_template
remove_column :currencies, :transaction_url_template, :string if column_exists? :currencies, :transaction_url_template
end
end

View File

@@ -0,0 +1,7 @@
class ChangeWalletStructure < ActiveRecord::Migration[4.2]
def change
change_column :wallets, :gateway, :string, limit: 20, default: '', null: false
add_column :wallets, :settings, :string,
limit: 1000, default: '{}', null: false, after: :gateway
end
end

View File

@@ -0,0 +1,19 @@
class ChangeLimitOfCurrencyIdAndMarketId < ActiveRecord::Migration[4.2]
def self.up
change_column :markets, :ask_unit, :string, limit: 10
change_column :markets, :bid_unit, :string, limit: 10
change_column :wallets, :currency_id, :string, limit: 10
change_column :markets, :id, :string, limit: 20
change_column :orders, :market_id, :string, limit: 20
change_column :trades, :market_id, :string, limit: 20
end
def self.down
change_column :markets, :ask_unit, :string, limit: 5
change_column :markets, :bid_unit, :string, limit: 5
change_column :wallets, :currency_id, :string, limit: 5
change_column :markets, :id, :string, limit: 10
change_column :orders, :market_id, :string, limit: 10
change_column :trades, :market_id, :string, limit: 10
end
end

View File

@@ -0,0 +1,14 @@
class RemoveFieldsFromCurrenices < ActiveRecord::Migration[4.2]
class Ccy < ActiveRecord::Base
serialize :options, JSON
self.table_name = 'currencies'
self.inheritance_column = :disabled
end
def change
Ccy.where(type: :coin).find_each do |ccy|
ccy.update_columns \
options: ccy.options.except('supports_hd_protocol', 'allow_multiple_deposit_addresses')
end
end
end

View File

@@ -0,0 +1,7 @@
class ChangeAddressLimit < ActiveRecord::Migration[4.2]
def change
change_column :deposits, :address, :string, limit: 95
change_column :withdraws, :rid, :string, limit: 95
change_column :payment_addresses, :address, :string, limit: 95
end
end

View File

@@ -0,0 +1,5 @@
class AddMinDepositAmountToCurrencies < ActiveRecord::Migration[4.2]
def change
add_column :currencies, :min_deposit_amount, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :quick_withdraw_limit
end
end

View File

@@ -0,0 +1,15 @@
class EnumerizeWalletKind < ActiveRecord::Migration[4.2]
def change
id_kind_hash = Wallet.pluck(:id, :kind).to_h
remove_column :wallets, :kind
add_column :wallets, :kind, :integer, limit: 4, null: false, after: :address
Wallet.find_each { |w| w.update!(kind: id_kind_hash[w.id]) }
add_index :wallets, :status
add_index :wallets, :kind
add_index :wallets, :currency_id
add_index :wallets, %i[kind currency_id status]
end
end

View File

@@ -0,0 +1,16 @@
class MemberField < ActiveRecord::Migration[4.2]
def change
change_table :members do |t|
t.remove :level
t.remove :sn
t.remove :disabled
t.remove :api_disabled
end
add_column :members, :uid, :string, after: :id, null: false, limit: 12
add_column :members, :level, :integer, after: :email, null: false
add_column :members, :role, :string, after: :level, null: false, limit: 16
add_column :members, :state, :string, after: :role, null: false, limit: 16
end
end

View File

@@ -0,0 +1,5 @@
class DropAuthentications < ActiveRecord::Migration[4.2]
def change
drop_table :authentications
end
end

View File

@@ -0,0 +1,13 @@
class CreateAssets < ActiveRecord::Migration[4.2]
def change
create_table :assets do |t|
t.integer :code, null: false
t.string :currency_id, null: false, index: true, foreign_key: true
t.references :reference, null: false, index: true, polymorphic: true
t.decimal :debit, null: false, default: 0, precision: 32, scale: 16
t.decimal :credit, null: false, default: 0, precision: 32, scale: 16
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,13 @@
class CreateExpenses < ActiveRecord::Migration[4.2]
def change
create_table :expenses do |t|
t.integer :code, null: false
t.string :currency_id, null: false, index: true, foreign_key: true
t.references :reference, null: false, index: true, polymorphic: true
t.decimal :debit, null: false, default: 0, precision: 32, scale: 16
t.decimal :credit, null: false, default: 0, precision: 32, scale: 16
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,14 @@
class CreateLiabilities < ActiveRecord::Migration[4.2]
def change
create_table :liabilities do |t|
t.integer :code, null: false
t.string :currency_id, null: false, index: true, foreign_key: true
t.integer :member_id, null: false, index: true, foreign_key: true
t.references :reference, null: false, index: true, polymorphic: true
t.decimal :debit, null: false, default: 0, precision: 32, scale: 16
t.decimal :credit, null: false, default: 0, precision: 32, scale: 16
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,13 @@
class CreateRevenues < ActiveRecord::Migration[4.2]
def change
create_table :revenues do |t|
t.integer :code, null: false
t.string :currency_id, null: false, index: true, foreign_key: true
t.references :reference, null: false, index: true, polymorphic: true
t.decimal :debit, null: false, default: 0, precision: 32, scale: 16
t.decimal :credit, null: false, default: 0, precision: 32, scale: 16
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,6 @@
class AddDailyWithdrawLimitToCurrencies < ActiveRecord::Migration[4.2]
def change
rename_column :currencies, :quick_withdraw_limit, :withdraw_limit_24h
add_column :currencies, :withdraw_limit_72h, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :withdraw_limit_24h
end
end

View File

@@ -0,0 +1,5 @@
class AddMinCollectionAmountToCurrencies < ActiveRecord::Migration[4.2]
def change
add_column :currencies, :min_collection_amount, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :min_deposit_amount
end
end

View File

@@ -0,0 +1,9 @@
class DropOperationsConstraints < ActiveRecord::Migration[4.2]
def change
%i[liabilities assets revenues expenses].each do |op|
change_column_null(op, :reference_id, true)
change_column_null(op, :reference_type, true)
end
end
end

View File

@@ -0,0 +1,9 @@
class AddMinWithdrawSumToCurrencies < ActiveRecord::Migration[4.2]
def change
add_column :currencies, :min_withdraw_amount, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :min_collection_amount
change_column :currencies, :min_deposit_amount, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :deposit_fee
change_column :currencies, :min_collection_amount, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :min_deposit_amount
change_column :currencies, :withdraw_fee, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :min_collection_amount
change_column :currencies, :min_withdraw_amount, :decimal, precision: 32, scale: 16, default: 0.0, null: false, after: :withdraw_fee
end
end

View File

@@ -0,0 +1,6 @@
class AddMinAmountToMarket < ActiveRecord::Migration[4.2]
def change
add_column :markets, :min_bid_amount, :decimal, null: false, default: 0, precision: 32, scale: 16, after: :min_ask
add_column :markets, :min_ask_amount, :decimal, null: false, default: 0, precision: 32, scale: 16, after: :min_bid_amount
end
end

View File

@@ -0,0 +1,11 @@
class CreateTransfers < ActiveRecord::Migration[4.2]
def change
create_table :transfers do |t|
t.integer :key, null: false, index: { unique: true }
t.string :kind, limit: 30, null: false, index: true
t.string :desc, limit: 255, default: ''
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,5 @@
class AddNameToCurrency < ActiveRecord::Migration[4.2]
def change
add_column :currencies, :name, :string, after: :id, default: nil
end
end

View File

@@ -0,0 +1,8 @@
class DropLiabilitiesNotNullAddRevenuesMemberId < ActiveRecord::Migration[4.2]
def change
change_column_null(:liabilities, :member_id, true)
add_column(:revenues, :member_id, :integer,
index: true, null: true, after: :currency_id)
end
end

View File

@@ -0,0 +1,16 @@
class CreateOperationsAccounts < ActiveRecord::Migration[4.2]
def change
create_table :operations_accounts do |t|
t.integer :code, null: false, limit: 3, index: { unique: true }
t.string :type, null: false, limit: 10, index: true
t.string :kind, null: false, limit: 30
t.string :currency_type, null: false, limit: 10, index: true
t.string :description, limit: 100
t.string :scope, null: false, limit: 10, index: true
t.timestamps null: false
end
add_index :operations_accounts, %i[type kind currency_type], unique: true
end
end

View File

@@ -0,0 +1,18 @@
class AddPositionToCurrenciesAndRenameMinAskMinBidToMarkets < ActiveRecord::Migration[4.2]
def change
unless column_exists?(:currencies, :position)
add_column :currencies, :position, :integer, default: 0, null: false, after: :withdraw_limit_72h
end
add_index :currencies, :position unless index_exists?(:currencies, :position)
rename_column :markets, :min_ask, :min_ask_price if column_exists?(:markets, :min_ask)
rename_column :markets, :max_bid, :max_bid_price if column_exists?(:markets, :max_bid)
change_column_null :markets, :max_bid_price, false, 0.0
change_column :markets, :min_ask_price, :decimal, precision: 32, scale: 16, after: :bid_fee
change_column :markets, :max_bid_price, :decimal, precision: 32, scale: 16, after: :min_ask_price, default: 0.0
change_column :markets, :min_ask_amount, :decimal, precision: 32, scale: 16, after: :max_bid_price
end
end

View File

@@ -0,0 +1,5 @@
class UpdateInvalidBlockchain < ActiveRecord::Migration[4.2]
def change
Blockchain.where(client: 'ethereum').update_all(client: 'geth')
end
end

View File

@@ -0,0 +1,9 @@
class AddMissingIndexesToOrderAndTrade < ActiveRecord::Migration[4.2]
def change
# index_trade_on_created_at is used in Trade #h24
add_index :trades, :created_at unless index_exists?(:trades, :created_at)
# index_orders_on_updated_at is used in API::V2::Market::Orders
add_index :orders, :updated_at unless index_exists?(:orders, :updated_at)
end
end

Some files were not shown because too many files have changed in this diff Show More