Initial commit
This commit is contained in:
80
db/influxdb.sql
Normal file
80
db/influxdb.sql
Normal 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;
|
||||
253
db/migrate/20180112151205_init_schema.rb
Normal file
253
db/migrate/20180112151205_init_schema.rb
Normal 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
|
||||
8
db/migrate/20180212115002_remove_know_your_customer.rb
Normal file
8
db/migrate/20180212115002_remove_know_your_customer.rb
Normal 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
|
||||
16
db/migrate/20180212115751_refactor_member_structure.rb
Normal file
16
db/migrate/20180212115751_refactor_member_structure.rb
Normal 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
|
||||
8
db/migrate/20180213160501_drop_assets.rb
Normal file
8
db/migrate/20180213160501_drop_assets.rb
Normal 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
|
||||
17
db/migrate/20180215124645_shorten_member_serial_number.rb
Normal file
17
db/migrate/20180215124645_shorten_member_serial_number.rb
Normal 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
|
||||
9
db/migrate/20180215131129_make_serial_number_unique.rb
Normal file
9
db/migrate/20180215131129_make_serial_number_unique.rb
Normal 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
|
||||
@@ -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
|
||||
19
db/migrate/20180215144646_add_currencies.rb
Normal file
19
db/migrate/20180215144646_add_currencies.rb
Normal 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
|
||||
10
db/migrate/20180216145412_remove_name_and_nickname.rb
Normal file
10
db/migrate/20180216145412_remove_name_and_nickname.rb
Normal 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
|
||||
12
db/migrate/20180227163417_good_currency_foreign_key.rb
Normal file
12
db/migrate/20180227163417_good_currency_foreign_key.rb
Normal 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
|
||||
@@ -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
|
||||
8
db/migrate/20180303211737_drop_api_tokens.rb
Normal file
8
db/migrate/20180303211737_drop_api_tokens.rb
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
8
db/migrate/20180315145436_remove_in_and_out.rb
Normal file
8
db/migrate/20180315145436_remove_in_and_out.rb
Normal 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
|
||||
@@ -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
|
||||
8
db/migrate/20180315185255_remove_key_from_currency.rb
Normal file
8
db/migrate/20180315185255_remove_key_from_currency.rb
Normal 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
|
||||
22
db/migrate/20180325001828_create_markets.rb
Normal file
22
db/migrate/20180325001828_create_markets.rb
Normal 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
|
||||
8
db/migrate/20180327020701_alter_currency.rb
Normal file
8
db/migrate/20180327020701_alter_currency.rb
Normal 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
|
||||
9
db/migrate/20180329145257_alter_trades_currency.rb
Normal file
9
db/migrate/20180329145257_alter_trades_currency.rb
Normal 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
|
||||
8
db/migrate/20180329145557_alter_orders_currency.rb
Normal file
8
db/migrate/20180329145557_alter_orders_currency.rb
Normal 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
|
||||
14
db/migrate/20180329154130_update_deprecated_currency_ids.rb
Normal file
14
db/migrate/20180329154130_update_deprecated_currency_ids.rb
Normal 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
|
||||
10
db/migrate/20180403115050_add_tid_to_deposit.rb
Normal file
10
db/migrate/20180403115050_add_tid_to_deposit.rb
Normal 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
|
||||
10
db/migrate/20180403134930_add_tid_to_withdraw.rb
Normal file
10
db/migrate/20180403134930_add_tid_to_withdraw.rb
Normal 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
|
||||
8
db/migrate/20180403135744_add_bid_to_withdraws.rb
Normal file
8
db/migrate/20180403135744_add_bid_to_withdraws.rb
Normal 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
|
||||
8
db/migrate/20180403145234_change_bid_to_rid.rb
Normal file
8
db/migrate/20180403145234_change_bid_to_rid.rb
Normal 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
|
||||
14
db/migrate/20180403231931_migrate_states.rb
Normal file
14
db/migrate/20180403231931_migrate_states.rb
Normal 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
|
||||
25
db/migrate/20180406080444_drop_withdraw_destinations.rb
Normal file
25
db/migrate/20180406080444_drop_withdraw_destinations.rb
Normal 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
|
||||
8
db/migrate/20180406185130_remove_sn_from_withdraw.rb
Normal file
8
db/migrate/20180406185130_remove_sn_from_withdraw.rb
Normal 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
|
||||
@@ -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
|
||||
8
db/migrate/20180409115144_drop_useless_deposit_state.rb
Normal file
8
db/migrate/20180409115144_drop_useless_deposit_state.rb
Normal 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
|
||||
33
db/migrate/20180409115902_refactor_deposit.rb
Normal file
33
db/migrate/20180409115902_refactor_deposit.rb
Normal 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
|
||||
8
db/migrate/20180416160438_add_fee_to_orders.rb
Normal file
8
db/migrate/20180416160438_add_fee_to_orders.rb
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
11
db/migrate/20180417175453_increase_fee_limits.rb
Normal file
11
db/migrate/20180417175453_increase_fee_limits.rb
Normal 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
|
||||
@@ -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
|
||||
11
db/migrate/20180425094920_limit_trading_fee.rb
Normal file
11
db/migrate/20180425094920_limit_trading_fee.rb
Normal 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
|
||||
@@ -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
|
||||
18
db/migrate/20180425224307_change_wallet_id_to_address_id.rb
Normal file
18
db/migrate/20180425224307_change_wallet_id_to_address_id.rb
Normal 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
|
||||
@@ -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
|
||||
29
db/migrate/20180501141718_case_sensitive_data.rb
Normal file
29
db/migrate/20180501141718_case_sensitive_data.rb
Normal 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
|
||||
14
db/migrate/20180516094307_improve_payment_address_model.rb
Normal file
14
db/migrate/20180516094307_improve_payment_address_model.rb
Normal 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
|
||||
9
db/migrate/20180516101606_improve_member_model.rb
Normal file
9
db/migrate/20180516101606_improve_member_model.rb
Normal 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
|
||||
15
db/migrate/20180516104042_improve_audit_model.rb
Normal file
15
db/migrate/20180516104042_improve_audit_model.rb
Normal 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
|
||||
16
db/migrate/20180516105035_improve_auth_model.rb
Normal file
16
db/migrate/20180516105035_improve_auth_model.rb
Normal 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
|
||||
17
db/migrate/20180516110336_improve_account_model.rb
Normal file
17
db/migrate/20180516110336_improve_account_model.rb
Normal 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
|
||||
29
db/migrate/20180516124235_improve_order_model.rb
Normal file
29
db/migrate/20180516124235_improve_order_model.rb
Normal 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
|
||||
9
db/migrate/20180516131005_improve_order_model2.rb
Normal file
9
db/migrate/20180516131005_improve_order_model2.rb
Normal 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
|
||||
25
db/migrate/20180516133138_improve_trade_model.rb
Normal file
25
db/migrate/20180516133138_improve_trade_model.rb
Normal 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
|
||||
5
db/migrate/20180517084245_currency_visible_to_enabled.rb
Normal file
5
db/migrate/20180517084245_currency_visible_to_enabled.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class CurrencyVisibleToEnabled < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
rename_column :currencies, :visible, :enabled
|
||||
end
|
||||
end
|
||||
27
db/migrate/20180517101842_improve_withdraw_model.rb
Normal file
27
db/migrate/20180517101842_improve_withdraw_model.rb
Normal 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
|
||||
11
db/migrate/20180517110003_improve_deposit_model.rb
Normal file
11
db/migrate/20180517110003_improve_deposit_model.rb
Normal 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
|
||||
@@ -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
|
||||
5
db/migrate/20180522121046_market_visible_to_enabled.rb
Normal file
5
db/migrate/20180522121046_market_visible_to_enabled.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class MarketVisibleToEnabled < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
rename_column :markets, :visible, :enabled
|
||||
end
|
||||
end
|
||||
5
db/migrate/20180522165830_drop_account_versions.rb
Normal file
5
db/migrate/20180522165830_drop_account_versions.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class DropAccountVersions < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
drop_table :account_versions
|
||||
end
|
||||
end
|
||||
8
db/migrate/20180524170927_improve_indexes.rb
Normal file
8
db/migrate/20180524170927_improve_indexes.rb
Normal 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
|
||||
6
db/migrate/20180525101406_improve_defaults_for_market.rb
Normal file
6
db/migrate/20180525101406_improve_defaults_for_market.rb
Normal 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
|
||||
46
db/migrate/20180529125011_replace_id_to_code.rb
Normal file
46
db/migrate/20180529125011_replace_id_to_code.rb
Normal 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
|
||||
27
db/migrate/20180530122201_change_members_level_type.rb
Normal file
27
db/migrate/20180530122201_change_members_level_type.rb
Normal 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
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddMissingIndexForAuthentications < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
add_index :authentications, [:provider, :member_id, :uid], unique: true
|
||||
end
|
||||
end
|
||||
27
db/migrate/20180613140856_multiple_deposit_addresses.rb
Normal file
27
db/migrate/20180613140856_multiple_deposit_addresses.rb
Normal 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
|
||||
@@ -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
|
||||
6
db/migrate/20180704103131_remove_solvency.rb
Normal file
6
db/migrate/20180704103131_remove_solvency.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class RemoveSolvency < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
drop_table :partial_trees
|
||||
drop_table :proofs
|
||||
end
|
||||
end
|
||||
6
db/migrate/20180704115110_remove_auditing.rb
Normal file
6
db/migrate/20180704115110_remove_auditing.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class RemoveAuditing < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
drop_table :audit_logs
|
||||
drop_table :versions
|
||||
end
|
||||
end
|
||||
19
db/migrate/20180708014826_create_blockchains.rb
Normal file
19
db/migrate/20180708014826_create_blockchains.rb
Normal 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
|
||||
15
db/migrate/20180708171446_create_wallets.rb
Normal file
15
db/migrate/20180708171446_create_wallets.rb
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
6
db/migrate/20180719172203_add_min_price_to_market.rb
Normal file
6
db/migrate/20180719172203_add_min_price_to_market.rb
Normal 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
|
||||
5
db/migrate/20180720165705_add_icon_url_to_currency.rb
Normal file
5
db/migrate/20180720165705_add_icon_url_to_currency.rb
Normal 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
|
||||
@@ -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
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddBlockchainKeyToWallet < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
add_column :wallets, :blockchain_key, :string, limit: 32, after: :id
|
||||
end
|
||||
end
|
||||
6
db/migrate/20180803144827_remove_urls_from_currencies.rb
Normal file
6
db/migrate/20180803144827_remove_urls_from_currencies.rb
Normal 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
|
||||
7
db/migrate/20180808144704_change_wallet_structure.rb
Normal file
7
db/migrate/20180808144704_change_wallet_structure.rb
Normal 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
|
||||
@@ -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
|
||||
14
db/migrate/20180905112301_remove_fields_from_currenices.rb
Normal file
14
db/migrate/20180905112301_remove_fields_from_currenices.rb
Normal 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
|
||||
7
db/migrate/20180925123806_change_address_limit.rb
Normal file
7
db/migrate/20180925123806_change_address_limit.rb
Normal 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
|
||||
@@ -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
|
||||
15
db/migrate/20181017114624_enumerize_wallet_kind.rb
Normal file
15
db/migrate/20181017114624_enumerize_wallet_kind.rb
Normal 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
|
||||
16
db/migrate/20181027192001_member_field.rb
Normal file
16
db/migrate/20181027192001_member_field.rb
Normal 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
|
||||
5
db/migrate/20181028000150_drop_authentications.rb
Normal file
5
db/migrate/20181028000150_drop_authentications.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class DropAuthentications < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
drop_table :authentications
|
||||
end
|
||||
end
|
||||
13
db/migrate/20181105102116_create_assets.rb
Normal file
13
db/migrate/20181105102116_create_assets.rb
Normal 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
|
||||
13
db/migrate/20181105102422_create_expenses.rb
Normal file
13
db/migrate/20181105102422_create_expenses.rb
Normal 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
|
||||
14
db/migrate/20181105102537_create_liabilities.rb
Normal file
14
db/migrate/20181105102537_create_liabilities.rb
Normal 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
|
||||
13
db/migrate/20181105120211_create_revenues.rb
Normal file
13
db/migrate/20181105120211_create_revenues.rb
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
9
db/migrate/20181210162905_drop_operations_constraints.rb
Normal file
9
db/migrate/20181210162905_drop_operations_constraints.rb
Normal 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
|
||||
|
||||
@@ -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
|
||||
6
db/migrate/20181219133822_add_min_amount_to_market.rb
Normal file
6
db/migrate/20181219133822_add_min_amount_to_market.rb
Normal 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
|
||||
11
db/migrate/20181226170925_create_transfers.rb
Normal file
11
db/migrate/20181226170925_create_transfers.rb
Normal 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
|
||||
5
db/migrate/20181229051129_add_name_to_currency.rb
Normal file
5
db/migrate/20181229051129_add_name_to_currency.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddNameToCurrency < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
add_column :currencies, :name, :string, after: :id, default: nil
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
16
db/migrate/20190115165813_create_operations_accounts.rb
Normal file
16
db/migrate/20190115165813_create_operations_accounts.rb
Normal 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
|
||||
@@ -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
|
||||
5
db/migrate/20190204142656_update_invalid_blockchain.rb
Normal file
5
db/migrate/20190204142656_update_invalid_blockchain.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class UpdateInvalidBlockchain < ActiveRecord::Migration[4.2]
|
||||
def change
|
||||
Blockchain.where(client: 'ethereum').update_all(client: 'geth')
|
||||
end
|
||||
end
|
||||
@@ -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
Reference in New Issue
Block a user