mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
Add SimpleFin database schema
- Create simplefin_items table for SimpleFin connections - Create simplefin_accounts table for account metadata - Add simplefin_account_id to accounts table for linking - Add external_id to transactions for deduplication - Enable encrypted storage of SimpleFin access URLs
This commit is contained in:
20
db/migrate/20250807143728_create_simplefin_items.rb
Normal file
20
db/migrate/20250807143728_create_simplefin_items.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class CreateSimplefinItems < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :simplefin_items, id: :uuid do |t|
|
||||
t.references :family, null: false, foreign_key: true, type: :uuid
|
||||
t.text :access_url
|
||||
t.string :name
|
||||
t.string :institution_id
|
||||
t.string :institution_name
|
||||
t.string :institution_url
|
||||
t.string :status, default: "good"
|
||||
t.boolean :scheduled_for_deletion, default: false
|
||||
|
||||
t.index :status
|
||||
t.jsonb :raw_payload
|
||||
t.jsonb :raw_institution_payload
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
20
db/migrate/20250807143819_create_simplefin_accounts.rb
Normal file
20
db/migrate/20250807143819_create_simplefin_accounts.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class CreateSimplefinAccounts < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :simplefin_accounts, id: :uuid do |t|
|
||||
t.references :simplefin_item, null: false, foreign_key: true, type: :uuid
|
||||
t.string :name
|
||||
t.string :account_id
|
||||
t.string :currency
|
||||
t.decimal :current_balance, precision: 19, scale: 4
|
||||
t.decimal :available_balance, precision: 19, scale: 4
|
||||
|
||||
t.index :account_id
|
||||
t.string :account_type
|
||||
t.string :account_subtype
|
||||
t.jsonb :raw_payload
|
||||
t.jsonb :raw_transactions_payload
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSimplefinAccountIdToAccounts < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_reference :accounts, :simplefin_account, null: true, foreign_key: true, type: :uuid
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddExternalIdToTransactions < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_column :transactions, :external_id, :string
|
||||
add_index :transactions, :external_id
|
||||
end
|
||||
end
|
||||
48
db/schema.rb
generated
48
db/schema.rb
generated
@@ -10,7 +10,9 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_07_24_115507) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_08_07_163541) do
|
||||
create_schema "sure_dev_schema"
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
@@ -29,12 +31,13 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_24_115507) 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, 'CreditCard'::character varying, '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)::text, ('CreditCard'::character varying)::text, ('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"
|
||||
t.jsonb "locked_attributes", default: {}
|
||||
t.string "status", default: "active"
|
||||
t.uuid "simplefin_account_id"
|
||||
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"
|
||||
@@ -44,6 +47,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_24_115507) do
|
||||
t.index ["family_id"], name: "index_accounts_on_family_id"
|
||||
t.index ["import_id"], name: "index_accounts_on_import_id"
|
||||
t.index ["plaid_account_id"], name: "index_accounts_on_plaid_account_id"
|
||||
t.index ["simplefin_account_id"], name: "index_accounts_on_simplefin_account_id"
|
||||
t.index ["status"], name: "index_accounts_on_status"
|
||||
end
|
||||
|
||||
@@ -672,6 +676,41 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_24_115507) do
|
||||
t.index ["var"], name: "index_settings_on_var", unique: true
|
||||
end
|
||||
|
||||
create_table "simplefin_accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "simplefin_item_id", null: false
|
||||
t.string "name"
|
||||
t.string "account_id"
|
||||
t.string "currency"
|
||||
t.decimal "current_balance", precision: 19, scale: 4
|
||||
t.decimal "available_balance", precision: 19, scale: 4
|
||||
t.string "account_type"
|
||||
t.string "account_subtype"
|
||||
t.jsonb "raw_payload"
|
||||
t.jsonb "raw_transactions_payload"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_simplefin_accounts_on_account_id"
|
||||
t.index ["simplefin_item_id"], name: "index_simplefin_accounts_on_simplefin_item_id"
|
||||
end
|
||||
|
||||
create_table "simplefin_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "family_id", null: false
|
||||
t.text "access_url"
|
||||
t.string "name"
|
||||
t.string "institution_id"
|
||||
t.string "institution_name"
|
||||
t.string "institution_url"
|
||||
t.string "status", default: "good"
|
||||
t.boolean "scheduled_for_deletion", default: false
|
||||
t.jsonb "raw_payload"
|
||||
t.jsonb "raw_institution_payload"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "pending_account_setup", default: false, null: false
|
||||
t.index ["family_id"], name: "index_simplefin_items_on_family_id"
|
||||
t.index ["status"], name: "index_simplefin_items_on_status"
|
||||
end
|
||||
|
||||
create_table "subscriptions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "family_id", null: false
|
||||
t.string "status", null: false
|
||||
@@ -756,7 +795,9 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_24_115507) do
|
||||
t.uuid "merchant_id"
|
||||
t.jsonb "locked_attributes", default: {}
|
||||
t.string "kind", default: "standard", null: false
|
||||
t.string "external_id"
|
||||
t.index ["category_id"], name: "index_transactions_on_category_id"
|
||||
t.index ["external_id"], name: "index_transactions_on_external_id"
|
||||
t.index ["kind"], name: "index_transactions_on_kind"
|
||||
t.index ["merchant_id"], name: "index_transactions_on_merchant_id"
|
||||
end
|
||||
@@ -827,6 +868,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_24_115507) do
|
||||
add_foreign_key "accounts", "families"
|
||||
add_foreign_key "accounts", "imports"
|
||||
add_foreign_key "accounts", "plaid_accounts"
|
||||
add_foreign_key "accounts", "simplefin_accounts"
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "api_keys", "users"
|
||||
@@ -864,6 +906,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_07_24_115507) do
|
||||
add_foreign_key "security_prices", "securities"
|
||||
add_foreign_key "sessions", "impersonation_sessions", column: "active_impersonator_session_id"
|
||||
add_foreign_key "sessions", "users"
|
||||
add_foreign_key "simplefin_accounts", "simplefin_items"
|
||||
add_foreign_key "simplefin_items", "families"
|
||||
add_foreign_key "subscriptions", "families"
|
||||
add_foreign_key "syncs", "syncs", column: "parent_id"
|
||||
add_foreign_key "taggings", "tags"
|
||||
|
||||
Reference in New Issue
Block a user