mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Add RejectedTransfer model, simplify auto matching (#1690)
* Allow transfers to match when inflow is after outflow * Simplify transfer auto matching with RejectedTransfer model * Validations * Reset migrations
This commit is contained in:
parent
0b4e314f58
commit
de90b29201
18 changed files with 221 additions and 79 deletions
44
db/migrate/20250124224316_create_rejected_transfers.rb
Normal file
44
db/migrate/20250124224316_create_rejected_transfers.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
class CreateRejectedTransfers < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :rejected_transfers, id: :uuid do |t|
|
||||
t.references :inflow_transaction, null: false, foreign_key: { to_table: :account_transactions }, type: :uuid
|
||||
t.references :outflow_transaction, null: false, foreign_key: { to_table: :account_transactions }, type: :uuid
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :rejected_transfers, [ :inflow_transaction_id, :outflow_transaction_id ], unique: true
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
execute <<~SQL
|
||||
INSERT INTO rejected_transfers (inflow_transaction_id, outflow_transaction_id, created_at, updated_at)
|
||||
SELECT
|
||||
inflow_transaction_id,
|
||||
outflow_transaction_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM transfers
|
||||
WHERE status = 'rejected'
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
DELETE FROM transfers
|
||||
WHERE status = 'rejected'
|
||||
SQL
|
||||
end
|
||||
|
||||
dir.down do
|
||||
execute <<~SQL
|
||||
INSERT INTO transfers (inflow_transaction_id, outflow_transaction_id, status, created_at, updated_at)
|
||||
SELECT
|
||||
inflow_transaction_id,
|
||||
outflow_transaction_id,
|
||||
'rejected',
|
||||
created_at,
|
||||
updated_at
|
||||
FROM rejected_transfers
|
||||
SQL
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
db/schema.rb
generated
14
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_01_20_210449) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_01_24_224316) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -527,6 +527,16 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_20_210449) do
|
|||
t.string "area_unit"
|
||||
end
|
||||
|
||||
create_table "rejected_transfers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "inflow_transaction_id", null: false
|
||||
t.uuid "outflow_transaction_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["inflow_transaction_id", "outflow_transaction_id"], name: "idx_on_inflow_transaction_id_outflow_transaction_id_412f8e7e26", unique: true
|
||||
t.index ["inflow_transaction_id"], name: "index_rejected_transfers_on_inflow_transaction_id"
|
||||
t.index ["outflow_transaction_id"], name: "index_rejected_transfers_on_outflow_transaction_id"
|
||||
end
|
||||
|
||||
create_table "securities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "ticker"
|
||||
t.string "name"
|
||||
|
@ -691,6 +701,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_20_210449) do
|
|||
add_foreign_key "merchants", "families"
|
||||
add_foreign_key "plaid_accounts", "plaid_items"
|
||||
add_foreign_key "plaid_items", "families"
|
||||
add_foreign_key "rejected_transfers", "account_transactions", column: "inflow_transaction_id"
|
||||
add_foreign_key "rejected_transfers", "account_transactions", column: "outflow_transaction_id"
|
||||
add_foreign_key "security_prices", "securities"
|
||||
add_foreign_key "sessions", "impersonation_sessions", column: "active_impersonator_session_id"
|
||||
add_foreign_key "sessions", "users"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue