mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 20:14:08 +00:00
FIX schema drift and snaptrade and mercury issues (#1232)
This commit is contained in:
@@ -4,16 +4,8 @@
|
||||
# account can be linked in multiple families. See: https://github.com/we-promise/sure/issues/740
|
||||
class ScopeSnaptradeAccountUniquenessToItem < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
remove_index :snaptrade_accounts, name: "index_snaptrade_accounts_on_account_id", if_exists: true
|
||||
remove_index :snaptrade_accounts, name: "index_snaptrade_accounts_on_snaptrade_account_id", if_exists: true
|
||||
|
||||
unless index_exists?(:snaptrade_accounts, [ :snaptrade_item_id, :account_id ], unique: true, name: "index_snaptrade_accounts_on_item_and_account_id")
|
||||
add_index :snaptrade_accounts,
|
||||
[ :snaptrade_item_id, :account_id ],
|
||||
unique: true,
|
||||
name: "index_snaptrade_accounts_on_item_and_account_id",
|
||||
where: "account_id IS NOT NULL"
|
||||
end
|
||||
unless index_exists?(:snaptrade_accounts, [ :snaptrade_item_id, :snaptrade_account_id ], unique: true, name: "index_snaptrade_accounts_on_item_and_snaptrade_account_id")
|
||||
add_index :snaptrade_accounts,
|
||||
[ :snaptrade_item_id, :snaptrade_account_id ],
|
||||
@@ -24,20 +16,12 @@ class ScopeSnaptradeAccountUniquenessToItem < ActiveRecord::Migration[7.2]
|
||||
end
|
||||
|
||||
def down
|
||||
if execute("SELECT 1 FROM snaptrade_accounts WHERE account_id IS NOT NULL GROUP BY account_id HAVING COUNT(DISTINCT snaptrade_item_id) > 1 LIMIT 1").any? ||
|
||||
execute("SELECT 1 FROM snaptrade_accounts WHERE snaptrade_account_id IS NOT NULL GROUP BY snaptrade_account_id HAVING COUNT(DISTINCT snaptrade_item_id) > 1 LIMIT 1").any?
|
||||
if execute("SELECT 1 FROM snaptrade_accounts WHERE snaptrade_account_id IS NOT NULL GROUP BY snaptrade_account_id HAVING COUNT(DISTINCT snaptrade_item_id) > 1 LIMIT 1").any?
|
||||
raise ActiveRecord::IrreversibleMigration,
|
||||
"Cannot rollback: cross-item duplicates exist in snaptrade_accounts. Remove duplicates first."
|
||||
end
|
||||
|
||||
remove_index :snaptrade_accounts, name: "index_snaptrade_accounts_on_item_and_account_id", if_exists: true
|
||||
remove_index :snaptrade_accounts, name: "index_snaptrade_accounts_on_item_and_snaptrade_account_id", if_exists: true
|
||||
unless index_exists?(:snaptrade_accounts, :account_id, name: "index_snaptrade_accounts_on_account_id")
|
||||
add_index :snaptrade_accounts, :account_id,
|
||||
name: "index_snaptrade_accounts_on_account_id",
|
||||
unique: true,
|
||||
where: "account_id IS NOT NULL"
|
||||
end
|
||||
unless index_exists?(:snaptrade_accounts, :snaptrade_account_id, name: "index_snaptrade_accounts_on_snaptrade_account_id")
|
||||
add_index :snaptrade_accounts, :snaptrade_account_id,
|
||||
name: "index_snaptrade_accounts_on_snaptrade_account_id",
|
||||
|
||||
11
db/schema.rb
generated
11
db/schema.rb
generated
@@ -49,8 +49,6 @@ ActiveRecord::Schema[7.2].define(version: 2026_03_14_131357) do
|
||||
t.string "institution_name"
|
||||
t.string "institution_domain"
|
||||
t.text "notes"
|
||||
t.jsonb "holdings_snapshot_data"
|
||||
t.datetime "holdings_snapshot_at"
|
||||
t.index ["accountable_id", "accountable_type"], name: "index_accounts_on_accountable_id_and_accountable_type"
|
||||
t.index ["accountable_type"], name: "index_accounts_on_accountable_type"
|
||||
t.index ["currency"], name: "index_accounts_on_currency"
|
||||
@@ -1243,7 +1241,6 @@ ActiveRecord::Schema[7.2].define(version: 2026_03_14_131357) do
|
||||
create_table "snaptrade_accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "snaptrade_item_id", null: false
|
||||
t.string "name"
|
||||
t.string "account_id"
|
||||
t.string "snaptrade_account_id"
|
||||
t.string "snaptrade_authorization_id"
|
||||
t.string "account_number"
|
||||
@@ -1265,7 +1262,6 @@ ActiveRecord::Schema[7.2].define(version: 2026_03_14_131357) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "activities_fetch_pending", default: false
|
||||
t.date "sync_start_date"
|
||||
t.index ["snaptrade_item_id", "account_id"], name: "index_snaptrade_accounts_on_item_and_account_id", unique: true, where: "(account_id IS NOT NULL)"
|
||||
t.index ["snaptrade_item_id", "snaptrade_account_id"], name: "index_snaptrade_accounts_on_item_and_snaptrade_account_id", unique: true, where: "(snaptrade_account_id IS NOT NULL)"
|
||||
t.index ["snaptrade_item_id"], name: "index_snaptrade_accounts_on_snaptrade_item_id"
|
||||
end
|
||||
@@ -1403,15 +1399,8 @@ ActiveRecord::Schema[7.2].define(version: 2026_03_14_131357) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "currency"
|
||||
t.jsonb "locked_attributes", default: {}
|
||||
t.decimal "realized_gain", precision: 19, scale: 4
|
||||
t.decimal "cost_basis_amount", precision: 19, scale: 4
|
||||
t.string "cost_basis_currency"
|
||||
t.integer "holding_period_days"
|
||||
t.string "realized_gain_confidence"
|
||||
t.string "realized_gain_currency"
|
||||
t.string "investment_activity_label"
|
||||
t.index ["investment_activity_label"], name: "index_trades_on_investment_activity_label"
|
||||
t.index ["realized_gain"], name: "index_trades_on_realized_gain_not_null", where: "(realized_gain IS NOT NULL)"
|
||||
t.index ["security_id"], name: "index_trades_on_security_id"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user