1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Fix Account Holding validation and synchronization (#1818)

* Fix Account Holding validation and synchronization

Fixes #1781

- Add comprehensive validations for Account::Holding
- Implement validation to ensure amount matches qty * price
- Update Account::Syncer to include qty and price during synchronization
- Add database constraints for holding attributes and calculations

* Remove database check constraints for Account Holdings

Align with project convention of keeping complex validations in ActiveRecord
- Remove database-level check constraints for quantity, price, and amount
- Maintain database-level null and unique constraints
- Prepare for more flexible validation in the model layer
This commit is contained in:
Josh Pigford 2025-02-07 10:42:01 -06:00 committed by GitHub
parent 0dc25cda22
commit cf23673003
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 67 additions and 9 deletions

12
db/schema.rb generated
View file

@ -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_02_06_151825) do
ActiveRecord::Schema[7.2].define(version: 2025_02_06_204404) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@ -55,11 +55,11 @@ ActiveRecord::Schema[7.2].define(version: 2025_02_06_151825) do
create_table "account_holdings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "account_id", null: false
t.uuid "security_id", null: false
t.date "date"
t.decimal "qty", precision: 19, scale: 4
t.decimal "price", precision: 19, scale: 4
t.decimal "amount", precision: 19, scale: 4
t.string "currency"
t.date "date", null: false
t.decimal "qty", precision: 19, scale: 4, null: false
t.decimal "price", precision: 19, scale: 4, null: false
t.decimal "amount", precision: 19, scale: 4, null: false
t.string "currency", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id", "security_id", "date", "currency"], name: "idx_on_account_id_security_id_date_currency_234024c8e3", unique: true