Asset
Core table for managing all types of assets in the system
Asset system overview
The asset system is the core component for tracking various types of financial assets. It uses a polymorphic design pattern where the asset table serves as the base table, with specific asset types having their own dedicated tables that reference it.
Asset table
Definition
The asset table is the foundation for all asset types in the system. It stores common attributes shared across all asset types while specific details are stored in type-specific tables.
Columns
| Column | Type | Description |
|---|---|---|
id | uuid | Primary key, auto-generated using gen_random_uuid() |
type | asset_types | The type of asset (see Asset Types below) |
space_id | uuid | Foreign key to the space table |
created_at | timestamp with time zone | Creation timestamp, defaults to current time |
updated_at | timestamp with time zone | Last update timestamp |
deleted_at | timestamp with time zone | Soft deletion timestamp |
filters | jsonb | JSON object storing asset filters and flags |
ownership_share | double precision | Percentage of ownership (0.01-100), defaults to 100 |
Primary key
asset__pkeyon (id)
Unique constraints
asset__id_keyon (id)
Foreign keys
asset__space_id_fkeyreferencesspace(id)
Asset Types
The system supports various types of assets through the asset_types enum:
enum asset_types {
'account'
'company_equity'
'liability'
'private_fund'
'private_investment'
'real_estate'
}Asset status
Assets can have different statuses managed through the asset_status enum:
enum asset_status {
'draft'
'active'
'archived'
'deleted'
}Views
asset_standing
The asset_standing view provides the current standing/value of assets. It combines information from various asset-specific tables and includes:
- Current valuations in both local and preferred currencies
- Asset metadata (names, logos, institutions)
- Type-specific details
- Exchange rate conversions
asset_value_history
The asset_value_history view maintains a historical record of asset values by:
- Tracking transactions and value updates
- Computing running balances
- Supporting different asset types
- Maintaining currency information
Filters
The filters JSONB column supports several flags:
deleted: Indicates if the asset is soft-deletedhidden: Controls asset visibilityin_net_worth: Determines if the asset should be included in net worth calculations
Triggers
event_delete_on_asset_soft_delete
Triggers when an asset is soft-deleted (when deleted_at is set). It:
- Updates the asset's filters
- Sets
deletedflag to true - Sets
hiddenflag to true - Sets
in_net_worthto false - Updates the
updated_attimestamp
Functions
Update ownership share
function update_asset_ownership_share(p_asset_id uuid, p_ownership_share double precision)Updates an asset's ownership share percentage:
- Validates the share is between 0.01 and 100
- Updates the asset's ownership_share
- Raises an exception if the asset is not found
Update asset visibility
function update_asset_hidden(asset_id uuid, hidden_value boolean)Updates the asset's hidden status in the filters JSONB:
- Sets the
hiddenflag in filters - Updates the
updated_attimestamp - Returns the updated asset record
Update net worth inclusion
function update_asset_in_net_worth(asset_id uuid, in_net_worth_value boolean)Updates whether the asset should be included in net worth calculations:
- Sets the
in_net_worthflag in filters - Returns the updated asset record
Usage notes
-
Soft deletion
- Use the soft deletion mechanism (
deleted_at) rather than hard deleting records - The trigger will automatically update relevant filters
- Use the soft deletion mechanism (
-
Value tracking
- Use the
asset_standingview for current values - Use
asset_value_historyfor historical analysis - Values are tracked in both local and preferred currencies
- Use the