mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Simplefin sync improvements (#240)
* Fix syncing issues with new connections and accounts.. - Keep SimpleFin institution metadata strictly per account (`simplefin_accounts.org_data`). - Relax `simplefin_items` institution constraints to allow creating items before org data exists. - Remove code that copied the first account’s `org` onto `simplefin_items`. * Improve Simplefin Sync • SimpleFin: family “Sync” includes SimpleFin items; importer does unbounded discovery (with pending=1 fallback) before windowed fetch, for both regular and first syncs. • Stop populating item‑level institution fields; keep institution metadata per account. • Relax NOT NULL on item institution fields. • Post‑sync dashboard broadcasts are now guarded (UI cannot fail the job). • Show a friendly “daily refresh limit” banner on the SimpleFin card when the latest sync is rate‑limited. • Add bin/rails sure:simplefin:debug[ITEM_ID] to print latest sync, snapshot account count, simplefin_accounts count, and unlinked list. * Fixed double‑quoted strings, spacing around array brackets and commas * chore: ignore local .junie files * - Broadcast error logs now include full backtraces - SimpleFin discovery logic deduplicated fixed - app/models/simplefin_item/importer.rb --Added a concise docstring for perform_account_discovery describing purpose, steps, and side‑effects. --Added a docstring for fetch_accounts_data describing params and return value.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
class RelaxSimplefinItemInstitutionConstraints < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
# SimpleFin doesn't guarantee institution metadata on first fetch,
|
||||
# so these fields must be optional.
|
||||
change_column_null :simplefin_items, :institution_id, true
|
||||
change_column_null :simplefin_items, :institution_name, true
|
||||
end
|
||||
|
||||
def down
|
||||
# Restoring NOT NULL could break existing rows that legitimately have no institution metadata.
|
||||
# We keep this reversible but conservative: only set NOT NULL if no NULLs exist.
|
||||
if execute("SELECT COUNT(*) FROM simplefin_items WHERE institution_id IS NULL").first["count"].to_i == 0
|
||||
change_column_null :simplefin_items, :institution_id, false
|
||||
end
|
||||
|
||||
if execute("SELECT COUNT(*) FROM simplefin_items WHERE institution_name IS NULL").first["count"].to_i == 0
|
||||
change_column_null :simplefin_items, :institution_name, false
|
||||
end
|
||||
end
|
||||
end
|
||||
7
db/schema.rb
generated
7
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_10_24_083624) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_10_25_095800) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
@@ -29,7 +29,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_10_24_083624) do
|
||||
t.uuid "accountable_id"
|
||||
t.decimal "balance", precision: 19, scale: 4
|
||||
t.string "currency"
|
||||
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY (ARRAY[('Loan'::character varying)::text, ('CreditCard'::character varying)::text, ('OtherLiability'::character varying)::text])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
|
||||
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Loan'::character varying, 'CreditCard'::character varying, 'OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
|
||||
t.uuid "import_id"
|
||||
t.uuid "plaid_account_id"
|
||||
t.decimal "cash_balance", precision: 19, scale: 4, default: "0.0"
|
||||
@@ -754,6 +754,9 @@ ActiveRecord::Schema[7.2].define(version: 2025_10_24_083624) do
|
||||
t.string "institution_color"
|
||||
t.date "sync_start_date"
|
||||
t.index ["family_id"], name: "index_simplefin_items_on_family_id"
|
||||
t.index ["institution_domain"], name: "index_simplefin_items_on_institution_domain"
|
||||
t.index ["institution_id"], name: "index_simplefin_items_on_institution_id"
|
||||
t.index ["institution_name"], name: "index_simplefin_items_on_institution_name"
|
||||
t.index ["status"], name: "index_simplefin_items_on_status"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user