diff --git a/apps/api/drizzle/0005_reminders_daily_last_3_days.sql b/apps/api/drizzle/0005_reminders_daily_last_3_days.sql new file mode 100644 index 0000000..757fd7c --- /dev/null +++ b/apps/api/drizzle/0005_reminders_daily_last_3_days.sql @@ -0,0 +1,9 @@ +-- Renewal reminders go out three times: two days before, the day before, and on the due day. +-- Only lists still on the old default change; a list someone customised is left as it is. +UPDATE "workspace" +SET "settings" = jsonb_set("settings", '{reminderOffsets}', '[2, 1, 0]'::jsonb) +WHERE "settings"->'reminderOffsets' = '[30, 14, 7, 3, 1, 0]'::jsonb; +--> statement-breakpoint +UPDATE "commitment" +SET "reminder_offsets" = ARRAY[2, 1, 0] +WHERE "reminder_offsets" = ARRAY[30, 14, 7, 3, 1, 0]; diff --git a/apps/api/drizzle/meta/0005_snapshot.json b/apps/api/drizzle/meta/0005_snapshot.json new file mode 100644 index 0000000..fed2e37 --- /dev/null +++ b/apps/api/drizzle/meta/0005_snapshot.json @@ -0,0 +1,9776 @@ +{ + "id": "a95a10ae-571e-4706-ac05-feb4daa52647", + "prevId": "0ee10610-e857-4bb9-847b-5eccef73dcc0", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.ai_usage": { + "name": "ai_usage", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "feature": { + "name": "feature", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "input_tokens": { + "name": "input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "output_tokens": { + "name": "output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cache_read_tokens": { + "name": "cache_read_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cache_write_tokens": { + "name": "cache_write_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric(12, 6)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "latency_ms": { + "name": "latency_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "ai_usage_workspace_idx": { + "name": "ai_usage_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "ai_usage_workspace_id_workspace_id_fk": { + "name": "ai_usage_workspace_id_workspace_id_fk", + "tableFrom": "ai_usage", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "ai_usage_user_id_auth_user_id_fk": { + "name": "ai_usage_user_id_auth_user_id_fk", + "tableFrom": "ai_usage", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.capture": { + "name": "capture", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "capture_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "stage": { + "name": "stage", + "type": "capture_stage", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'received'" + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "input_text": { + "name": "input_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "extraction": { + "name": "extraction", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric(12, 6)", + "primaryKey": false, + "notNull": false + }, + "is_subscription": { + "name": "is_subscription", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "draft_transaction_ids": { + "name": "draft_transaction_ids", + "type": "uuid[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::uuid[]" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "capture_workspace_idx": { + "name": "capture_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "capture_workspace_id_workspace_id_fk": { + "name": "capture_workspace_id_workspace_id_fk", + "tableFrom": "capture", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "capture_file_id_file_id_fk": { + "name": "capture_file_id_file_id_fk", + "tableFrom": "capture", + "columnsFrom": [ + "file_id" + ], + "tableTo": "file", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "capture_created_by_auth_user_id_fk": { + "name": "capture_created_by_auth_user_id_fk", + "tableFrom": "capture", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_message": { + "name": "copilot_message", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "thread_id": { + "name": "thread_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "copilot_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_message_thread_idx": { + "name": "copilot_message_thread_idx", + "columns": [ + { + "expression": "thread_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "copilot_message_thread_id_copilot_thread_id_fk": { + "name": "copilot_message_thread_id_copilot_thread_id_fk", + "tableFrom": "copilot_message", + "columnsFrom": [ + "thread_id" + ], + "tableTo": "copilot_thread", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_thread": { + "name": "copilot_thread", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_thread_user_idx": { + "name": "copilot_thread_user_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "copilot_thread_workspace_id_workspace_id_fk": { + "name": "copilot_thread_workspace_id_workspace_id_fk", + "tableFrom": "copilot_thread", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "copilot_thread_user_id_auth_user_id_fk": { + "name": "copilot_thread_user_id_auth_user_id_fk", + "tableFrom": "copilot_thread", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.inbox_item": { + "name": "inbox_item", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "inbox_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "inbox_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "severity": { + "name": "severity", + "type": "severity", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'info'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dedupe_key": { + "name": "dedupe_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "snoozed_until": { + "name": "snoozed_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "resolved_by": { + "name": "resolved_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "inbox_item_dedupe_idx": { + "name": "inbox_item_dedupe_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dedupe_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + }, + "inbox_item_workspace_status_idx": { + "name": "inbox_item_workspace_status_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "inbox_item_workspace_id_workspace_id_fk": { + "name": "inbox_item_workspace_id_workspace_id_fk", + "tableFrom": "inbox_item", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.report": { + "name": "report", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "report_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "period_start": { + "name": "period_start", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "period_end": { + "name": "period_end", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "narrative": { + "name": "narrative", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "narrative_source": { + "name": "narrative_source", + "type": "narrative_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'template'" + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "filters": { + "name": "filters", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "report_workspace_idx": { + "name": "report_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "report_workspace_id_workspace_id_fk": { + "name": "report_workspace_id_workspace_id_fk", + "tableFrom": "report", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "report_created_by_auth_user_id_fk": { + "name": "report_created_by_auth_user_id_fk", + "tableFrom": "report", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_account": { + "name": "auth_account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_account_user_idx": { + "name": "auth_account_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "auth_account_user_id_auth_user_id_fk": { + "name": "auth_account_user_id_auth_user_id_fk", + "tableFrom": "auth_account", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_rate_limit": { + "name": "auth_rate_limit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "count": { + "name": "count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "last_request": { + "name": "last_request", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "auth_rate_limit_key_unique": { + "name": "auth_rate_limit_key_unique", + "columns": [ + "key" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_session": { + "name": "auth_session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "impersonated_by": { + "name": "impersonated_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_session_user_idx": { + "name": "auth_session_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "auth_session_user_id_auth_user_id_fk": { + "name": "auth_session_user_id_auth_user_id_fk", + "tableFrom": "auth_session", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "auth_session_token_unique": { + "name": "auth_session_token_unique", + "columns": [ + "token" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_two_factor": { + "name": "auth_two_factor", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backup_codes": { + "name": "backup_codes", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "failed_verification_count": { + "name": "failed_verification_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "auth_two_factor_user_idx": { + "name": "auth_two_factor_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "auth_two_factor_secret_idx": { + "name": "auth_two_factor_secret_idx", + "columns": [ + { + "expression": "secret", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "auth_two_factor_user_id_auth_user_id_fk": { + "name": "auth_two_factor_user_id_auth_user_id_fk", + "tableFrom": "auth_two_factor", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_user": { + "name": "auth_user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'user'" + }, + "banned": { + "name": "banned", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "ban_reason": { + "name": "ban_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ban_expires": { + "name": "ban_expires", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "two_factor_enabled": { + "name": "two_factor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "auth_user_email_unique": { + "name": "auth_user_email_unique", + "columns": [ + "email" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.auth_verification": { + "name": "auth_verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "auth_verification_identifier_idx": { + "name": "auth_verification_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.employee": { + "name": "employee", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "counterparty_id": { + "name": "counterparty_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "employment_type": { + "name": "employment_type", + "type": "employment_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'full_time'" + }, + "salary": { + "name": "salary", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "pay_day": { + "name": "pay_day", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "default_project_id": { + "name": "default_project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "employee_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "employee_workspace_idx": { + "name": "employee_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "employee_workspace_id_workspace_id_fk": { + "name": "employee_workspace_id_workspace_id_fk", + "tableFrom": "employee", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "employee_counterparty_id_counterparty_id_fk": { + "name": "employee_counterparty_id_counterparty_id_fk", + "tableFrom": "employee", + "columnsFrom": [ + "counterparty_id" + ], + "tableTo": "counterparty", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "employee_default_project_id_project_id_fk": { + "name": "employee_default_project_id_project_id_fk", + "tableFrom": "employee", + "columnsFrom": [ + "default_project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "employee_account_id_financial_account_id_fk": { + "name": "employee_account_id_financial_account_id_fk", + "tableFrom": "employee", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payroll_item": { + "name": "payroll_item", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "employee_id": { + "name": "employee_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "gross": { + "name": "gross", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "deductions": { + "name": "deductions", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "net": { + "name": "net", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "transaction_id": { + "name": "transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "payroll_item_run_idx": { + "name": "payroll_item_run_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "payroll_item_workspace_id_workspace_id_fk": { + "name": "payroll_item_workspace_id_workspace_id_fk", + "tableFrom": "payroll_item", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "payroll_item_run_id_payroll_run_id_fk": { + "name": "payroll_item_run_id_payroll_run_id_fk", + "tableFrom": "payroll_item", + "columnsFrom": [ + "run_id" + ], + "tableTo": "payroll_run", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "payroll_item_employee_id_employee_id_fk": { + "name": "payroll_item_employee_id_employee_id_fk", + "tableFrom": "payroll_item", + "columnsFrom": [ + "employee_id" + ], + "tableTo": "employee", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "payroll_item_project_id_project_id_fk": { + "name": "payroll_item_project_id_project_id_fk", + "tableFrom": "payroll_item", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "payroll_item_account_id_financial_account_id_fk": { + "name": "payroll_item_account_id_financial_account_id_fk", + "tableFrom": "payroll_item", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "payroll_item_transaction_id_transaction_id_fk": { + "name": "payroll_item_transaction_id_transaction_id_fk", + "tableFrom": "payroll_item", + "columnsFrom": [ + "transaction_id" + ], + "tableTo": "transaction", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payroll_run": { + "name": "payroll_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "period": { + "name": "period", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "payroll_run_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "pay_date": { + "name": "pay_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "total_net": { + "name": "total_net", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "posted_at": { + "name": "posted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "payroll_run_workspace_id_workspace_id_fk": { + "name": "payroll_run_workspace_id_workspace_id_fk", + "tableFrom": "payroll_run", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "payroll_run_created_by_auth_user_id_fk": { + "name": "payroll_run_created_by_auth_user_id_fk", + "tableFrom": "payroll_run", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "payroll_run_period_unique": { + "name": "payroll_run_period_unique", + "columns": [ + "workspace_id", + "period" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.api_key": { + "name": "api_key", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "prefix": { + "name": "prefix", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key_hash": { + "name": "key_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{read}'::text[]" + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "api_key_workspace_idx": { + "name": "api_key_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "api_key_workspace_id_workspace_id_fk": { + "name": "api_key_workspace_id_workspace_id_fk", + "tableFrom": "api_key", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "api_key_created_by_auth_user_id_fk": { + "name": "api_key_created_by_auth_user_id_fk", + "tableFrom": "api_key", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "api_key_key_hash_unique": { + "name": "api_key_key_hash_unique", + "columns": [ + "key_hash" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_log": { + "name": "audit_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actor_type": { + "name": "actor_type", + "type": "actor_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'user'" + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "before": { + "name": "before", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "after": { + "name": "after", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "audit_log_workspace_created_idx": { + "name": "audit_log_workspace_created_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "audit_log_entity_idx": { + "name": "audit_log_entity_idx", + "columns": [ + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "audit_log_workspace_id_workspace_id_fk": { + "name": "audit_log_workspace_id_workspace_id_fk", + "tableFrom": "audit_log", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.domain_event": { + "name": "domain_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "domain_event_pending_idx": { + "name": "domain_event_pending_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "where": "processed_at is null", + "concurrently": false + }, + "domain_event_workspace_idx": { + "name": "domain_event_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "domain_event_workspace_id_workspace_id_fk": { + "name": "domain_event_workspace_id_workspace_id_fk", + "tableFrom": "domain_event", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.file": { + "name": "file", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "storage_backend": { + "name": "storage_backend", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "sha256": { + "name": "sha256", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "file_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'attachment'" + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "file_workspace_sha_idx": { + "name": "file_workspace_sha_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "file_workspace_id_workspace_id_fk": { + "name": "file_workspace_id_workspace_id_fk", + "tableFrom": "file", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "file_uploaded_by_auth_user_id_fk": { + "name": "file_uploaded_by_auth_user_id_fk", + "tableFrom": "file", + "columnsFrom": [ + "uploaded_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "file_storage_key_unique": { + "name": "file_storage_key_unique", + "columns": [ + "storage_key" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.job": { + "name": "job", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "status": { + "name": "status", + "type": "job_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "run_at": { + "name": "run_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5 + }, + "locked_at": { + "name": "locked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "locked_by": { + "name": "locked_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dedupe_key": { + "name": "dedupe_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "job_status_run_at_idx": { + "name": "job_status_run_at_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "run_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "job_dedupe_active_idx": { + "name": "job_dedupe_active_idx", + "columns": [ + { + "expression": "dedupe_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "dedupe_key is not null and status in ('queued', 'running')", + "concurrently": false + } + }, + "foreignKeys": { + "job_workspace_id_workspace_id_fk": { + "name": "job_workspace_id_workspace_id_fk", + "tableFrom": "job", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notification": { + "name": "notification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "severity": { + "name": "severity", + "type": "severity", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'info'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "link": { + "name": "link", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "dedupe_key": { + "name": "dedupe_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "emailed_at": { + "name": "emailed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "notification_dedupe_idx": { + "name": "notification_dedupe_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dedupe_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + }, + "notification_user_idx": { + "name": "notification_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "read_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "notification_workspace_id_workspace_id_fk": { + "name": "notification_workspace_id_workspace_id_fk", + "tableFrom": "notification", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "notification_user_id_auth_user_id_fk": { + "name": "notification_user_id_auth_user_id_fk", + "tableFrom": "notification", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.platform_setting": { + "name": "platform_setting", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "platform_setting_updated_by_auth_user_id_fk": { + "name": "platform_setting_updated_by_auth_user_id_fk", + "tableFrom": "platform_setting", + "columnsFrom": [ + "updated_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rate_limit": { + "name": "rate_limit", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "window_start": { + "name": "window_start", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "count": { + "name": "count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_settings": { + "name": "user_settings", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "active_workspace_id": { + "name": "active_workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "preferences": { + "name": "preferences", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "user_settings_user_id_auth_user_id_fk": { + "name": "user_settings_user_id_auth_user_id_fk", + "tableFrom": "user_settings", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "user_settings_active_workspace_id_workspace_id_fk": { + "name": "user_settings_active_workspace_id_workspace_id_fk", + "tableFrom": "user_settings", + "columnsFrom": [ + "active_workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_member": { + "name": "workspace_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "member_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'owner'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_member_unique": { + "name": "workspace_member_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + }, + "workspace_member_user_idx": { + "name": "workspace_member_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "workspace_member_workspace_id_workspace_id_fk": { + "name": "workspace_member_workspace_id_workspace_id_fk", + "tableFrom": "workspace_member", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "workspace_member_user_id_auth_user_id_fk": { + "name": "workspace_member_user_id_auth_user_id_fk", + "tableFrom": "workspace_member", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace": { + "name": "workspace", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "workspace_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "base_currency": { + "name": "base_currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true, + "default": "'BDT'" + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'Asia/Dhaka'" + }, + "fiscal_year_start_month": { + "name": "fiscal_year_start_month", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "settings": { + "name": "settings", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.import_batch": { + "name": "import_batch", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "format": { + "name": "format", + "type": "import_format", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "import_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'uploaded'" + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "headers": { + "name": "headers", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "mapping": { + "name": "mapping", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "options": { + "name": "options", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "total_rows": { + "name": "total_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "valid_rows": { + "name": "valid_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "invalid_rows": { + "name": "invalid_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "duplicate_rows": { + "name": "duplicate_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "imported_rows": { + "name": "imported_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "import_batch_workspace_idx": { + "name": "import_batch_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "import_batch_workspace_id_workspace_id_fk": { + "name": "import_batch_workspace_id_workspace_id_fk", + "tableFrom": "import_batch", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "import_batch_file_id_file_id_fk": { + "name": "import_batch_file_id_file_id_fk", + "tableFrom": "import_batch", + "columnsFrom": [ + "file_id" + ], + "tableTo": "file", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "import_batch_account_id_financial_account_id_fk": { + "name": "import_batch_account_id_financial_account_id_fk", + "tableFrom": "import_batch", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "import_batch_created_by_auth_user_id_fk": { + "name": "import_batch_created_by_auth_user_id_fk", + "tableFrom": "import_batch", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.import_row": { + "name": "import_row", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "batch_id": { + "name": "batch_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "row_number": { + "name": "row_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "raw": { + "name": "raw", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "normalized": { + "name": "normalized", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "import_row_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'valid'" + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "duplicate_of_id": { + "name": "duplicate_of_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "transaction_id": { + "name": "transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "import_row_batch_idx": { + "name": "import_row_batch_idx", + "columns": [ + { + "expression": "batch_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "row_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "import_row_workspace_id_workspace_id_fk": { + "name": "import_row_workspace_id_workspace_id_fk", + "tableFrom": "import_row", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "import_row_batch_id_import_batch_id_fk": { + "name": "import_row_batch_id_import_batch_id_fk", + "tableFrom": "import_row", + "columnsFrom": [ + "batch_id" + ], + "tableTo": "import_batch", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.integration_connection": { + "name": "integration_connection", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "connection_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'connected'" + }, + "credentials_encrypted": { + "name": "credentials_encrypted", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "sync_frequency": { + "name": "sync_frequency", + "type": "sync_frequency", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'daily'" + }, + "trust_level": { + "name": "trust_level", + "type": "trust_level", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'review'" + }, + "sync_cursor": { + "name": "sync_cursor", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_success_at": { + "name": "last_success_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error_at": { + "name": "last_error_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "records_total": { + "name": "records_total", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "webhook_public_id": { + "name": "webhook_public_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "webhook_secret_encrypted": { + "name": "webhook_secret_encrypted", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "integration_connection_workspace_idx": { + "name": "integration_connection_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "integration_connection_workspace_id_workspace_id_fk": { + "name": "integration_connection_workspace_id_workspace_id_fk", + "tableFrom": "integration_connection", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "integration_connection_account_id_financial_account_id_fk": { + "name": "integration_connection_account_id_financial_account_id_fk", + "tableFrom": "integration_connection", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "integration_connection_project_id_project_id_fk": { + "name": "integration_connection_project_id_project_id_fk", + "tableFrom": "integration_connection", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "integration_connection_created_by_auth_user_id_fk": { + "name": "integration_connection_created_by_auth_user_id_fk", + "tableFrom": "integration_connection", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "integration_connection_webhook_public_id_unique": { + "name": "integration_connection_webhook_public_id_unique", + "columns": [ + "webhook_public_id" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sync_run": { + "name": "sync_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "trigger": { + "name": "trigger", + "type": "sync_trigger", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "sync_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "records_found": { + "name": "records_found", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created": { + "name": "created", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated": { + "name": "updated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "skipped": { + "name": "skipped", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "duplicates": { + "name": "duplicates", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "errors": { + "name": "errors", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error_details": { + "name": "error_details", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "cursor_before": { + "name": "cursor_before", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "cursor_after": { + "name": "cursor_after", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "triggered_by": { + "name": "triggered_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "sync_run_connection_idx": { + "name": "sync_run_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "sync_run_workspace_idx": { + "name": "sync_run_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "sync_run_workspace_id_workspace_id_fk": { + "name": "sync_run_workspace_id_workspace_id_fk", + "tableFrom": "sync_run", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "sync_run_connection_id_integration_connection_id_fk": { + "name": "sync_run_connection_id_integration_connection_id_fk", + "tableFrom": "sync_run", + "columnsFrom": [ + "connection_id" + ], + "tableTo": "integration_connection", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook_event": { + "name": "webhook_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider_event_id": { + "name": "provider_event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "signature_valid": { + "name": "signature_valid", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "webhook_event_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'received'" + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "received_at": { + "name": "received_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "webhook_event_workspace_idx": { + "name": "webhook_event_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "received_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "webhook_event_workspace_id_workspace_id_fk": { + "name": "webhook_event_workspace_id_workspace_id_fk", + "tableFrom": "webhook_event", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "webhook_event_connection_id_integration_connection_id_fk": { + "name": "webhook_event_connection_id_integration_connection_id_fk", + "tableFrom": "webhook_event", + "columnsFrom": [ + "connection_id" + ], + "tableTo": "integration_connection", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "webhook_event_unique": { + "name": "webhook_event_unique", + "columns": [ + "connection_id", + "provider_event_id" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.budget": { + "name": "budget", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "period": { + "name": "period", + "type": "budget_period", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'monthly'" + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "alert_threshold": { + "name": "alert_threshold", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 80 + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "budget_workspace_idx": { + "name": "budget_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "budget_workspace_id_workspace_id_fk": { + "name": "budget_workspace_id_workspace_id_fk", + "tableFrom": "budget", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "budget_category_id_category_id_fk": { + "name": "budget_category_id_category_id_fk", + "tableFrom": "budget", + "columnsFrom": [ + "category_id" + ], + "tableTo": "category", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "budget_project_id_project_id_fk": { + "name": "budget_project_id_project_id_fk", + "tableFrom": "budget", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.category": { + "name": "category", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "category_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_system": { + "name": "is_system", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "category_workspace_idx": { + "name": "category_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "category_workspace_id_workspace_id_fk": { + "name": "category_workspace_id_workspace_id_fk", + "tableFrom": "category", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "category_parent_id_category_id_fk": { + "name": "category_parent_id_category_id_fk", + "tableFrom": "category", + "columnsFrom": [ + "parent_id" + ], + "tableTo": "category", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "category_name_unique": { + "name": "category_name_unique", + "columns": [ + "workspace_id", + "kind", + "parent_id", + "name" + ], + "nullsNotDistinct": true + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.counterparty": { + "name": "counterparty", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "normalized_name": { + "name": "normalized_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "counterparty_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'merchant'" + }, + "aliases": { + "name": "aliases", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "default_category_id": { + "name": "default_category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "default_project_id": { + "name": "default_project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "default_account_id": { + "name": "default_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "confirmations": { + "name": "confirmations", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "counterparty_name_unique": { + "name": "counterparty_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "normalized_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "counterparty_workspace_id_workspace_id_fk": { + "name": "counterparty_workspace_id_workspace_id_fk", + "tableFrom": "counterparty", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "counterparty_default_category_id_category_id_fk": { + "name": "counterparty_default_category_id_category_id_fk", + "tableFrom": "counterparty", + "columnsFrom": [ + "default_category_id" + ], + "tableTo": "category", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "counterparty_default_project_id_project_id_fk": { + "name": "counterparty_default_project_id_project_id_fk", + "tableFrom": "counterparty", + "columnsFrom": [ + "default_project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "counterparty_default_account_id_financial_account_id_fk": { + "name": "counterparty_default_account_id_financial_account_id_fk", + "tableFrom": "counterparty", + "columnsFrom": [ + "default_account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.exchange_rate": { + "name": "exchange_rate", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "from_currency": { + "name": "from_currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "to_currency": { + "name": "to_currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "rate": { + "name": "rate", + "type": "numeric(20, 10)", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "rate_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "exchange_rate_unique": { + "name": "exchange_rate_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "from_currency", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "to_currency", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "exchange_rate_workspace_id_workspace_id_fk": { + "name": "exchange_rate_workspace_id_workspace_id_fk", + "tableFrom": "exchange_rate", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.financial_account": { + "name": "financial_account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "account_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "institution": { + "name": "institution", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mask": { + "name": "mask", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "opening_balance": { + "name": "opening_balance", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "opening_date": { + "name": "opening_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "credit_limit": { + "name": "credit_limit", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "is_liability": { + "name": "is_liability", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "include_in_net_worth": { + "name": "include_in_net_worth", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "status": { + "name": "status", + "type": "account_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_reconciled_at": { + "name": "last_reconciled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_reconciled_balance": { + "name": "last_reconciled_balance", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "financial_account_workspace_idx": { + "name": "financial_account_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "financial_account_workspace_id_workspace_id_fk": { + "name": "financial_account_workspace_id_workspace_id_fk", + "tableFrom": "financial_account", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ledger_entry": { + "name": "ledger_entry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "transaction_id": { + "name": "transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "base_amount": { + "name": "base_amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "ledger_entry_account_date_idx": { + "name": "ledger_entry_account_date_idx", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "ledger_entry_workspace_date_idx": { + "name": "ledger_entry_workspace_date_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "ledger_entry_transaction_idx": { + "name": "ledger_entry_transaction_idx", + "columns": [ + { + "expression": "transaction_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "ledger_entry_workspace_id_workspace_id_fk": { + "name": "ledger_entry_workspace_id_workspace_id_fk", + "tableFrom": "ledger_entry", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "ledger_entry_transaction_id_transaction_id_fk": { + "name": "ledger_entry_transaction_id_transaction_id_fk", + "tableFrom": "ledger_entry", + "columnsFrom": [ + "transaction_id" + ], + "tableTo": "transaction", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "ledger_entry_account_id_financial_account_id_fk": { + "name": "ledger_entry_account_id_financial_account_id_fk", + "tableFrom": "ledger_entry", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project": { + "name": "project", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "project_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "budget_amount": { + "name": "budget_amount", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "project_workspace_idx": { + "name": "project_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "project_workspace_id_workspace_id_fk": { + "name": "project_workspace_id_workspace_id_fk", + "tableFrom": "project", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "project_name_unique": { + "name": "project_name_unique", + "columns": [ + "workspace_id", + "name" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rule": { + "name": "rule", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 100 + }, + "match": { + "name": "match", + "type": "rule_match", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'all'" + }, + "conditions": { + "name": "conditions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "actions": { + "name": "actions", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "stop_processing": { + "name": "stop_processing", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "times_applied": { + "name": "times_applied", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_applied_at": { + "name": "last_applied_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "rule_workspace_idx": { + "name": "rule_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "priority", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "rule_workspace_id_workspace_id_fk": { + "name": "rule_workspace_id_workspace_id_fk", + "tableFrom": "rule", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "rule_created_by_auth_user_id_fk": { + "name": "rule_created_by_auth_user_id_fk", + "tableFrom": "rule", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.transaction_attachment": { + "name": "transaction_attachment", + "schema": "", + "columns": { + "transaction_id": { + "name": "transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "file_id": { + "name": "file_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "transaction_attachment_transaction_id_transaction_id_fk": { + "name": "transaction_attachment_transaction_id_transaction_id_fk", + "tableFrom": "transaction_attachment", + "columnsFrom": [ + "transaction_id" + ], + "tableTo": "transaction", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "transaction_attachment_file_id_file_id_fk": { + "name": "transaction_attachment_file_id_file_id_fk", + "tableFrom": "transaction_attachment", + "columnsFrom": [ + "file_id" + ], + "tableTo": "file", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": { + "transaction_attachment_transaction_id_file_id_pk": { + "name": "transaction_attachment_transaction_id_file_id_pk", + "columns": [ + "transaction_id", + "file_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.transaction": { + "name": "transaction", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "transaction_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "transaction_direction", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "transaction_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'posted'" + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "to_account_id": { + "name": "to_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "account_amount": { + "name": "account_amount", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "to_account_amount": { + "name": "to_account_amount", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "fx_rate": { + "name": "fx_rate", + "type": "numeric(20, 10)", + "primaryKey": false, + "notNull": false + }, + "base_amount": { + "name": "base_amount", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "base_currency": { + "name": "base_currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "merchant": { + "name": "merchant", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "counterparty_id": { + "name": "counterparty_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference": { + "name": "reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "transaction_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "source_ref": { + "name": "source_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_key": { + "name": "external_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "attachment_file_id": { + "name": "attachment_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "ai_confidence": { + "name": "ai_confidence", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "cost_basis": { + "name": "cost_basis", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "liability_id": { + "name": "liability_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "receivable_id": { + "name": "receivable_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "investment_id": { + "name": "investment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "linked_transaction_id": { + "name": "linked_transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "review_reason": { + "name": "review_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "posted_at": { + "name": "posted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "voided_at": { + "name": "voided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "transaction_workspace_date_idx": { + "name": "transaction_workspace_date_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_workspace_status_idx": { + "name": "transaction_workspace_status_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_workspace_type_date_idx": { + "name": "transaction_workspace_type_date_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_account_date_idx": { + "name": "transaction_account_date_idx", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_category_date_idx": { + "name": "transaction_category_date_idx", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_project_date_idx": { + "name": "transaction_project_date_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_counterparty_idx": { + "name": "transaction_counterparty_idx", + "columns": [ + { + "expression": "counterparty_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_workspace_source_idx": { + "name": "transaction_workspace_source_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_workspace_created_idx": { + "name": "transaction_workspace_created_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_workspace_reference_idx": { + "name": "transaction_workspace_reference_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reference", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_connection_idx": { + "name": "transaction_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "transaction_external_key_idx": { + "name": "transaction_external_key_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "external_key is not null", + "concurrently": false + } + }, + "foreignKeys": { + "transaction_workspace_id_workspace_id_fk": { + "name": "transaction_workspace_id_workspace_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "transaction_account_id_financial_account_id_fk": { + "name": "transaction_account_id_financial_account_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "transaction_to_account_id_financial_account_id_fk": { + "name": "transaction_to_account_id_financial_account_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "to_account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "restrict" + }, + "transaction_counterparty_id_counterparty_id_fk": { + "name": "transaction_counterparty_id_counterparty_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "counterparty_id" + ], + "tableTo": "counterparty", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_category_id_category_id_fk": { + "name": "transaction_category_id_category_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "category_id" + ], + "tableTo": "category", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_project_id_project_id_fk": { + "name": "transaction_project_id_project_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_connection_id_integration_connection_id_fk": { + "name": "transaction_connection_id_integration_connection_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "connection_id" + ], + "tableTo": "integration_connection", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_attachment_file_id_file_id_fk": { + "name": "transaction_attachment_file_id_file_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "attachment_file_id" + ], + "tableTo": "file", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_liability_id_liability_id_fk": { + "name": "transaction_liability_id_liability_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "liability_id" + ], + "tableTo": "liability", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_receivable_id_receivable_id_fk": { + "name": "transaction_receivable_id_receivable_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "receivable_id" + ], + "tableTo": "receivable", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_asset_id_asset_id_fk": { + "name": "transaction_asset_id_asset_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "asset_id" + ], + "tableTo": "asset", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_investment_id_investment_id_fk": { + "name": "transaction_investment_id_investment_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "investment_id" + ], + "tableTo": "investment", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_linked_transaction_id_transaction_id_fk": { + "name": "transaction_linked_transaction_id_transaction_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "linked_transaction_id" + ], + "tableTo": "transaction", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "transaction_created_by_auth_user_id_fk": { + "name": "transaction_created_by_auth_user_id_fk", + "tableFrom": "transaction", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "transaction_amount_positive": { + "name": "transaction_amount_positive", + "value": "\"transaction\".\"amount\" > 0" + }, + "transaction_posted_complete": { + "name": "transaction_posted_complete", + "value": "\"transaction\".\"status\" <> 'posted' or (\"transaction\".\"account_id\" is not null and \"transaction\".\"account_amount\" is not null and \"transaction\".\"base_amount\" is not null)" + }, + "transaction_transfer_destination": { + "name": "transaction_transfer_destination", + "value": "\"transaction\".\"type\" <> 'transfer' or \"transaction\".\"status\" <> 'posted' or (\"transaction\".\"to_account_id\" is not null and \"transaction\".\"to_account_amount\" is not null and \"transaction\".\"to_account_id\" <> \"transaction\".\"account_id\")" + } + }, + "isRLSEnabled": false + }, + "public.commitment_occurrence": { + "name": "commitment_occurrence", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "commitment_id": { + "name": "commitment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "occurrence_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'scheduled'" + }, + "transaction_id": { + "name": "transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "paid_on": { + "name": "paid_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "paid_amount": { + "name": "paid_amount", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "commitment_occurrence_workspace_idx": { + "name": "commitment_occurrence_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "commitment_occurrence_transaction_idx": { + "name": "commitment_occurrence_transaction_idx", + "columns": [ + { + "expression": "transaction_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "transaction_id is not null", + "concurrently": false + } + }, + "foreignKeys": { + "commitment_occurrence_workspace_id_workspace_id_fk": { + "name": "commitment_occurrence_workspace_id_workspace_id_fk", + "tableFrom": "commitment_occurrence", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "commitment_occurrence_commitment_id_commitment_id_fk": { + "name": "commitment_occurrence_commitment_id_commitment_id_fk", + "tableFrom": "commitment_occurrence", + "columnsFrom": [ + "commitment_id" + ], + "tableTo": "commitment", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "commitment_occurrence_transaction_id_transaction_id_fk": { + "name": "commitment_occurrence_transaction_id_transaction_id_fk", + "tableFrom": "commitment_occurrence", + "columnsFrom": [ + "transaction_id" + ], + "tableTo": "transaction", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "commitment_occurrence_due_unique": { + "name": "commitment_occurrence_due_unique", + "columns": [ + "commitment_id", + "due_date" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.commitment": { + "name": "commitment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "commitment_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "transaction_direction", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'out'" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counterparty_id": { + "name": "counterparty_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "payee": { + "name": "payee", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "frequency": { + "name": "frequency", + "type": "commitment_frequency", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "interval_count": { + "name": "interval_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "interval_unit": { + "name": "interval_unit", + "type": "interval_unit", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "next_due_date": { + "name": "next_due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "liability_id": { + "name": "liability_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "auto_pay": { + "name": "auto_pay", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "status": { + "name": "status", + "type": "commitment_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "reminder_offsets": { + "name": "reminder_offsets", + "type": "integer[]", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "commitment_workspace_due_idx": { + "name": "commitment_workspace_due_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_due_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "commitment_workspace_kind_idx": { + "name": "commitment_workspace_kind_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "commitment_project_idx": { + "name": "commitment_project_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "commitment_workspace_id_workspace_id_fk": { + "name": "commitment_workspace_id_workspace_id_fk", + "tableFrom": "commitment", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "commitment_counterparty_id_counterparty_id_fk": { + "name": "commitment_counterparty_id_counterparty_id_fk", + "tableFrom": "commitment", + "columnsFrom": [ + "counterparty_id" + ], + "tableTo": "counterparty", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "commitment_account_id_financial_account_id_fk": { + "name": "commitment_account_id_financial_account_id_fk", + "tableFrom": "commitment", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "commitment_category_id_category_id_fk": { + "name": "commitment_category_id_category_id_fk", + "tableFrom": "commitment", + "columnsFrom": [ + "category_id" + ], + "tableTo": "category", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "commitment_project_id_project_id_fk": { + "name": "commitment_project_id_project_id_fk", + "tableFrom": "commitment", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "commitment_liability_id_liability_id_fk": { + "name": "commitment_liability_id_liability_id_fk", + "tableFrom": "commitment", + "columnsFrom": [ + "liability_id" + ], + "tableTo": "liability", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "commitment_created_by_auth_user_id_fk": { + "name": "commitment_created_by_auth_user_id_fk", + "tableFrom": "commitment", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.goal_contribution": { + "name": "goal_contribution", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "goal_id": { + "name": "goal_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "transaction_id": { + "name": "transaction_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "goal_contribution_goal_idx": { + "name": "goal_contribution_goal_idx", + "columns": [ + { + "expression": "goal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "goal_contribution_workspace_id_workspace_id_fk": { + "name": "goal_contribution_workspace_id_workspace_id_fk", + "tableFrom": "goal_contribution", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "goal_contribution_goal_id_goal_id_fk": { + "name": "goal_contribution_goal_id_goal_id_fk", + "tableFrom": "goal_contribution", + "columnsFrom": [ + "goal_id" + ], + "tableTo": "goal", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "goal_contribution_transaction_id_transaction_id_fk": { + "name": "goal_contribution_transaction_id_transaction_id_fk", + "tableFrom": "goal_contribution", + "columnsFrom": [ + "transaction_id" + ], + "tableTo": "transaction", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "goal_contribution_created_by_auth_user_id_fk": { + "name": "goal_contribution_created_by_auth_user_id_fk", + "tableFrom": "goal_contribution", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.goal": { + "name": "goal", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "goal_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_amount": { + "name": "target_amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "target_date": { + "name": "target_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "priority": { + "name": "priority", + "type": "priority", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'medium'" + }, + "monthly_plan": { + "name": "monthly_plan", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "starting_amount": { + "name": "starting_amount", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "linked_account_id": { + "name": "linked_account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "image_file_id": { + "name": "image_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "goal_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "achieved_at": { + "name": "achieved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "goal_workspace_idx": { + "name": "goal_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "goal_workspace_id_workspace_id_fk": { + "name": "goal_workspace_id_workspace_id_fk", + "tableFrom": "goal", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "goal_linked_account_id_financial_account_id_fk": { + "name": "goal_linked_account_id_financial_account_id_fk", + "tableFrom": "goal", + "columnsFrom": [ + "linked_account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "goal_image_file_id_file_id_fk": { + "name": "goal_image_file_id_file_id_fk", + "tableFrom": "goal", + "columnsFrom": [ + "image_file_id" + ], + "tableTo": "file", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.subscription": { + "name": "subscription", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "commitment_id": { + "name": "commitment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "plan_name": { + "name": "plan_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "purchase_date": { + "name": "purchase_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "trial_ends_on": { + "name": "trial_ends_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "expiry_date": { + "name": "expiry_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "cancellation_deadline": { + "name": "cancellation_deadline", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "auto_renew": { + "name": "auto_renew", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "status": { + "name": "status", + "type": "subscription_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "external_provider_id": { + "name": "external_provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attachment_file_id": { + "name": "attachment_file_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "subscription_workspace_idx": { + "name": "subscription_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "subscription_workspace_id_workspace_id_fk": { + "name": "subscription_workspace_id_workspace_id_fk", + "tableFrom": "subscription", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "subscription_commitment_id_commitment_id_fk": { + "name": "subscription_commitment_id_commitment_id_fk", + "tableFrom": "subscription", + "columnsFrom": [ + "commitment_id" + ], + "tableTo": "commitment", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "subscription_attachment_file_id_file_id_fk": { + "name": "subscription_attachment_file_id_file_id_fk", + "tableFrom": "subscription", + "columnsFrom": [ + "attachment_file_id" + ], + "tableTo": "file", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "subscription_commitment_id_unique": { + "name": "subscription_commitment_id_unique", + "columns": [ + "commitment_id" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_payment": { + "name": "billing_payment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_ref": { + "name": "provider_ref", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_payment_id": { + "name": "provider_payment_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "plan": { + "name": "plan", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "interval": { + "name": "interval", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credits": { + "name": "credits", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "paid_at": { + "name": "paid_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "receipt_url": { + "name": "receipt_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "billing_payment_provider_ref_idx": { + "name": "billing_payment_provider_ref_idx", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + }, + "billing_payment_user_idx": { + "name": "billing_payment_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "billing_payment_user_id_auth_user_id_fk": { + "name": "billing_payment_user_id_auth_user_id_fk", + "tableFrom": "billing_payment", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.billing_subscription": { + "name": "billing_subscription", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "plan": { + "name": "plan", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'free'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_customer_id": { + "name": "provider_customer_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_subscription_id": { + "name": "provider_subscription_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "interval": { + "name": "interval", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "current_period_start": { + "name": "current_period_start", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "current_period_end": { + "name": "current_period_end", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "trial_ends_at": { + "name": "trial_ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancel_at_period_end": { + "name": "cancel_at_period_end", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "billing_subscription_provider_idx": { + "name": "billing_subscription_provider_idx", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_subscription_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "billing_subscription_user_id_auth_user_id_fk": { + "name": "billing_subscription_user_id_auth_user_id_fk", + "tableFrom": "billing_subscription", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "billing_subscription_user_id_unique": { + "name": "billing_subscription_user_id_unique", + "columns": [ + "user_id" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.credit_transaction": { + "name": "credit_transaction", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "credits": { + "name": "credits", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric(14, 6)", + "primaryKey": false, + "notNull": false + }, + "ai_usage_id": { + "name": "ai_usage_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "payment_id": { + "name": "payment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credit_transaction_user_idx": { + "name": "credit_transaction_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "credit_transaction_payment_idx": { + "name": "credit_transaction_payment_idx", + "columns": [ + { + "expression": "payment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "credit_transaction_user_id_auth_user_id_fk": { + "name": "credit_transaction_user_id_auth_user_id_fk", + "tableFrom": "credit_transaction", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "credit_transaction_workspace_id_workspace_id_fk": { + "name": "credit_transaction_workspace_id_workspace_id_fk", + "tableFrom": "credit_transaction", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "credit_transaction_payment_id_billing_payment_id_fk": { + "name": "credit_transaction_payment_id_billing_payment_id_fk", + "tableFrom": "credit_transaction", + "columnsFrom": [ + "payment_id" + ], + "tableTo": "billing_payment", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "credit_transaction_created_by_auth_user_id_fk": { + "name": "credit_transaction_created_by_auth_user_id_fk", + "tableFrom": "credit_transaction", + "columnsFrom": [ + "created_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.platform_audit_log": { + "name": "platform_audit_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actor_email": { + "name": "actor_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "platform_audit_created_idx": { + "name": "platform_audit_created_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "platform_audit_target_idx": { + "name": "platform_audit_target_idx", + "columns": [ + { + "expression": "target_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scheduler_run": { + "name": "scheduler_run", + "schema": "", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slot": { + "name": "slot", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "instance": { + "name": "instance", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "scheduler_run_name_slot_pk": { + "name": "scheduler_run_name_slot_pk", + "columns": [ + "name", + "slot" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.support_request": { + "name": "support_request", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "page": { + "name": "page", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "support_request_status_idx": { + "name": "support_request_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "support_request_user_id_auth_user_id_fk": { + "name": "support_request_user_id_auth_user_id_fk", + "tableFrom": "support_request", + "columnsFrom": [ + "user_id" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "support_request_workspace_id_workspace_id_fk": { + "name": "support_request_workspace_id_workspace_id_fk", + "tableFrom": "support_request", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_invitation": { + "name": "workspace_invitation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "member_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "token_hash": { + "name": "token_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "invited_by": { + "name": "invited_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_by": { + "name": "accepted_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_invitation_pending_idx": { + "name": "workspace_invitation_pending_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "status = 'pending'", + "concurrently": false + }, + "workspace_invitation_email_idx": { + "name": "workspace_invitation_email_idx", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "workspace_invitation_workspace_id_workspace_id_fk": { + "name": "workspace_invitation_workspace_id_workspace_id_fk", + "tableFrom": "workspace_invitation", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "workspace_invitation_invited_by_auth_user_id_fk": { + "name": "workspace_invitation_invited_by_auth_user_id_fk", + "tableFrom": "workspace_invitation", + "columnsFrom": [ + "invited_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "workspace_invitation_accepted_by_auth_user_id_fk": { + "name": "workspace_invitation_accepted_by_auth_user_id_fk", + "tableFrom": "workspace_invitation", + "columnsFrom": [ + "accepted_by" + ], + "tableTo": "auth_user", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "workspace_invitation_token_hash_unique": { + "name": "workspace_invitation_token_hash_unique", + "columns": [ + "token_hash" + ], + "nullsNotDistinct": false + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.asset_valuation": { + "name": "asset_valuation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "asset_valuation_asset_date_idx": { + "name": "asset_valuation_asset_date_idx", + "columns": [ + { + "expression": "asset_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "asset_valuation_workspace_id_workspace_id_fk": { + "name": "asset_valuation_workspace_id_workspace_id_fk", + "tableFrom": "asset_valuation", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "asset_valuation_asset_id_asset_id_fk": { + "name": "asset_valuation_asset_id_asset_id_fk", + "tableFrom": "asset_valuation", + "columnsFrom": [ + "asset_id" + ], + "tableTo": "asset", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.asset": { + "name": "asset", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "asset_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "purchase_price": { + "name": "purchase_price", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "purchase_date": { + "name": "purchase_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "current_value": { + "name": "current_value", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "valued_at": { + "name": "valued_at", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "owner": { + "name": "owner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "asset_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'owned'" + }, + "sold_on": { + "name": "sold_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "sold_amount": { + "name": "sold_amount", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "asset_workspace_idx": { + "name": "asset_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "asset_workspace_id_workspace_id_fk": { + "name": "asset_workspace_id_workspace_id_fk", + "tableFrom": "asset", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "asset_project_id_project_id_fk": { + "name": "asset_project_id_project_id_fk", + "tableFrom": "asset", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.investment_valuation": { + "name": "investment_valuation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "investment_id": { + "name": "investment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "investment_valuation_investment_date_idx": { + "name": "investment_valuation_investment_date_idx", + "columns": [ + { + "expression": "investment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "investment_valuation_workspace_id_workspace_id_fk": { + "name": "investment_valuation_workspace_id_workspace_id_fk", + "tableFrom": "investment_valuation", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "investment_valuation_investment_id_investment_id_fk": { + "name": "investment_valuation_investment_id_investment_id_fk", + "tableFrom": "investment_valuation", + "columnsFrom": [ + "investment_id" + ], + "tableTo": "investment", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.investment": { + "name": "investment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "investment_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "institution": { + "name": "institution", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "opened_on": { + "name": "opened_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "maturity_date": { + "name": "maturity_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "interest_rate": { + "name": "interest_rate", + "type": "numeric(7, 4)", + "primaryKey": false, + "notNull": false + }, + "opening_cost_basis": { + "name": "opening_cost_basis", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "current_value": { + "name": "current_value", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "valued_at": { + "name": "valued_at", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "investment_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "investment_workspace_idx": { + "name": "investment_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + } + }, + "foreignKeys": { + "investment_workspace_id_workspace_id_fk": { + "name": "investment_workspace_id_workspace_id_fk", + "tableFrom": "investment", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.liability": { + "name": "liability", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "liability_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "counterparty_id": { + "name": "counterparty_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "counterparty_name": { + "name": "counterparty_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "principal": { + "name": "principal", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "opening_outstanding": { + "name": "opening_outstanding", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "interest_rate": { + "name": "interest_rate", + "type": "numeric(7, 4)", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "liability_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_key": { + "name": "external_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "liability_workspace_idx": { + "name": "liability_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "liability_external_key_idx": { + "name": "liability_external_key_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "external_key is not null", + "concurrently": false + } + }, + "foreignKeys": { + "liability_workspace_id_workspace_id_fk": { + "name": "liability_workspace_id_workspace_id_fk", + "tableFrom": "liability", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "liability_counterparty_id_counterparty_id_fk": { + "name": "liability_counterparty_id_counterparty_id_fk", + "tableFrom": "liability", + "columnsFrom": [ + "counterparty_id" + ], + "tableTo": "counterparty", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "liability_category_id_category_id_fk": { + "name": "liability_category_id_category_id_fk", + "tableFrom": "liability", + "columnsFrom": [ + "category_id" + ], + "tableTo": "category", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "liability_project_id_project_id_fk": { + "name": "liability_project_id_project_id_fk", + "tableFrom": "liability", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "liability_account_id_financial_account_id_fk": { + "name": "liability_account_id_financial_account_id_fk", + "tableFrom": "liability", + "columnsFrom": [ + "account_id" + ], + "tableTo": "financial_account", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.receivable": { + "name": "receivable", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "receivable_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'invoice'" + }, + "counterparty_id": { + "name": "counterparty_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "counterparty_name": { + "name": "counterparty_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference": { + "name": "reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": true + }, + "issue_date": { + "name": "issue_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "receivable_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "external_key": { + "name": "external_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "receivable_workspace_status_idx": { + "name": "receivable_workspace_status_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "receivable_project_idx": { + "name": "receivable_project_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "with": {}, + "method": "btree", + "concurrently": false + }, + "receivable_external_key_idx": { + "name": "receivable_external_key_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "with": {}, + "method": "btree", + "where": "external_key is not null", + "concurrently": false + } + }, + "foreignKeys": { + "receivable_workspace_id_workspace_id_fk": { + "name": "receivable_workspace_id_workspace_id_fk", + "tableFrom": "receivable", + "columnsFrom": [ + "workspace_id" + ], + "tableTo": "workspace", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "cascade" + }, + "receivable_counterparty_id_counterparty_id_fk": { + "name": "receivable_counterparty_id_counterparty_id_fk", + "tableFrom": "receivable", + "columnsFrom": [ + "counterparty_id" + ], + "tableTo": "counterparty", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "receivable_project_id_project_id_fk": { + "name": "receivable_project_id_project_id_fk", + "tableFrom": "receivable", + "columnsFrom": [ + "project_id" + ], + "tableTo": "project", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "receivable_category_id_category_id_fk": { + "name": "receivable_category_id_category_id_fk", + "tableFrom": "receivable", + "columnsFrom": [ + "category_id" + ], + "tableTo": "category", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + }, + "receivable_connection_id_integration_connection_id_fk": { + "name": "receivable_connection_id_integration_connection_id_fk", + "tableFrom": "receivable", + "columnsFrom": [ + "connection_id" + ], + "tableTo": "integration_connection", + "columnsTo": [ + "id" + ], + "onUpdate": "no action", + "onDelete": "set null" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.account_kind": { + "name": "account_kind", + "schema": "public", + "values": [ + "bank", + "cash", + "mobile_wallet", + "card", + "digital_wallet", + "payment_processor", + "savings", + "loan", + "other" + ] + }, + "public.account_status": { + "name": "account_status", + "schema": "public", + "values": [ + "active", + "archived" + ] + }, + "public.actor_type": { + "name": "actor_type", + "schema": "public", + "values": [ + "user", + "system", + "integration", + "ai", + "api" + ] + }, + "public.asset_kind": { + "name": "asset_kind", + "schema": "public", + "values": [ + "equipment", + "electronics", + "vehicle", + "property", + "land", + "jewelry", + "business_asset", + "other" + ] + }, + "public.asset_status": { + "name": "asset_status", + "schema": "public", + "values": [ + "owned", + "sold", + "disposed" + ] + }, + "public.budget_period": { + "name": "budget_period", + "schema": "public", + "values": [ + "monthly", + "quarterly", + "yearly", + "total" + ] + }, + "public.capture_kind": { + "name": "capture_kind", + "schema": "public", + "values": [ + "screenshot", + "receipt", + "text", + "voice", + "pdf", + "email" + ] + }, + "public.capture_stage": { + "name": "capture_stage", + "schema": "public", + "values": [ + "received", + "processing", + "suggested", + "confirmed", + "posted", + "failed", + "discarded" + ] + }, + "public.category_kind": { + "name": "category_kind", + "schema": "public", + "values": [ + "expense", + "income" + ] + }, + "public.commitment_frequency": { + "name": "commitment_frequency", + "schema": "public", + "values": [ + "once", + "weekly", + "monthly", + "quarterly", + "half_yearly", + "yearly", + "custom" + ] + }, + "public.commitment_kind": { + "name": "commitment_kind", + "schema": "public", + "values": [ + "subscription", + "salary", + "payroll", + "rent", + "loan_payment", + "insurance", + "tax", + "utility", + "domain", + "hosting", + "software", + "contractor", + "education", + "income", + "custom" + ] + }, + "public.commitment_status": { + "name": "commitment_status", + "schema": "public", + "values": [ + "active", + "paused", + "ended" + ] + }, + "public.connection_status": { + "name": "connection_status", + "schema": "public", + "values": [ + "connected", + "syncing", + "error", + "needs_attention", + "disconnected" + ] + }, + "public.copilot_role": { + "name": "copilot_role", + "schema": "public", + "values": [ + "user", + "assistant" + ] + }, + "public.counterparty_kind": { + "name": "counterparty_kind", + "schema": "public", + "values": [ + "merchant", + "customer", + "vendor", + "person", + "employee", + "institution", + "other" + ] + }, + "public.employee_status": { + "name": "employee_status", + "schema": "public", + "values": [ + "active", + "inactive" + ] + }, + "public.employment_type": { + "name": "employment_type", + "schema": "public", + "values": [ + "full_time", + "part_time", + "contractor", + "intern" + ] + }, + "public.file_kind": { + "name": "file_kind", + "schema": "public", + "values": [ + "screenshot", + "receipt", + "statement", + "import", + "attachment", + "report", + "other" + ] + }, + "public.goal_kind": { + "name": "goal_kind", + "schema": "public", + "values": [ + "savings", + "emergency_fund", + "asset_purchase", + "business_capital", + "travel", + "investment", + "education", + "dream_asset", + "custom" + ] + }, + "public.goal_status": { + "name": "goal_status", + "schema": "public", + "values": [ + "active", + "achieved", + "paused", + "archived" + ] + }, + "public.import_format": { + "name": "import_format", + "schema": "public", + "values": [ + "csv", + "xlsx", + "pdf" + ] + }, + "public.import_row_status": { + "name": "import_row_status", + "schema": "public", + "values": [ + "valid", + "invalid", + "duplicate", + "imported", + "skipped" + ] + }, + "public.import_status": { + "name": "import_status", + "schema": "public", + "values": [ + "uploaded", + "mapped", + "previewed", + "importing", + "completed", + "failed", + "cancelled" + ] + }, + "public.inbox_kind": { + "name": "inbox_kind", + "schema": "public", + "values": [ + "duplicate", + "recurring_candidate", + "subscription_candidate", + "anomaly", + "integration_error", + "budget_warning", + "price_change", + "renewal", + "large_transaction", + "forecast_warning", + "receivable_overdue", + "observation" + ] + }, + "public.inbox_status": { + "name": "inbox_status", + "schema": "public", + "values": [ + "open", + "resolved", + "dismissed", + "snoozed" + ] + }, + "public.interval_unit": { + "name": "interval_unit", + "schema": "public", + "values": [ + "day", + "week", + "month", + "year" + ] + }, + "public.investment_kind": { + "name": "investment_kind", + "schema": "public", + "values": [ + "stock", + "mutual_fund", + "fixed_deposit", + "savings_certificate", + "bond", + "dps", + "gold", + "crypto", + "real_estate", + "business_equity", + "retirement", + "other" + ] + }, + "public.investment_status": { + "name": "investment_status", + "schema": "public", + "values": [ + "active", + "closed" + ] + }, + "public.job_status": { + "name": "job_status", + "schema": "public", + "values": [ + "queued", + "running", + "succeeded", + "failed", + "dead" + ] + }, + "public.liability_kind": { + "name": "liability_kind", + "schema": "public", + "values": [ + "loan", + "credit", + "personal_debt", + "business_debt", + "payable", + "mortgage", + "other" + ] + }, + "public.liability_status": { + "name": "liability_status", + "schema": "public", + "values": [ + "active", + "paid_off", + "overdue", + "cancelled" + ] + }, + "public.member_role": { + "name": "member_role", + "schema": "public", + "values": [ + "owner", + "admin", + "member", + "viewer" + ] + }, + "public.narrative_source": { + "name": "narrative_source", + "schema": "public", + "values": [ + "ai", + "template" + ] + }, + "public.occurrence_status": { + "name": "occurrence_status", + "schema": "public", + "values": [ + "scheduled", + "paid", + "skipped", + "cancelled" + ] + }, + "public.payroll_run_status": { + "name": "payroll_run_status", + "schema": "public", + "values": [ + "draft", + "posted" + ] + }, + "public.priority": { + "name": "priority", + "schema": "public", + "values": [ + "low", + "medium", + "high" + ] + }, + "public.project_status": { + "name": "project_status", + "schema": "public", + "values": [ + "active", + "paused", + "completed", + "archived" + ] + }, + "public.rate_source": { + "name": "rate_source", + "schema": "public", + "values": [ + "manual", + "seed", + "api", + "transaction" + ] + }, + "public.receivable_kind": { + "name": "receivable_kind", + "schema": "public", + "values": [ + "invoice", + "loan", + "other" + ] + }, + "public.receivable_status": { + "name": "receivable_status", + "schema": "public", + "values": [ + "pending", + "partially_paid", + "paid", + "overdue", + "cancelled" + ] + }, + "public.report_kind": { + "name": "report_kind", + "schema": "public", + "values": [ + "weekly", + "monthly", + "quarterly", + "custom" + ] + }, + "public.rule_match": { + "name": "rule_match", + "schema": "public", + "values": [ + "all", + "any" + ] + }, + "public.severity": { + "name": "severity", + "schema": "public", + "values": [ + "info", + "success", + "warning", + "critical" + ] + }, + "public.subscription_status": { + "name": "subscription_status", + "schema": "public", + "values": [ + "trial", + "active", + "renewal_due", + "renewed", + "cancellation_pending", + "cancelled", + "expired", + "paused" + ] + }, + "public.sync_frequency": { + "name": "sync_frequency", + "schema": "public", + "values": [ + "manual", + "hourly", + "daily" + ] + }, + "public.sync_status": { + "name": "sync_status", + "schema": "public", + "values": [ + "running", + "succeeded", + "partial", + "failed" + ] + }, + "public.sync_trigger": { + "name": "sync_trigger", + "schema": "public", + "values": [ + "initial", + "incremental", + "manual", + "scheduled", + "webhook", + "retry" + ] + }, + "public.transaction_direction": { + "name": "transaction_direction", + "schema": "public", + "values": [ + "in", + "out" + ] + }, + "public.transaction_source": { + "name": "transaction_source", + "schema": "public", + "values": [ + "manual", + "screenshot", + "receipt", + "text", + "voice", + "csv", + "excel", + "pdf", + "integration", + "webhook", + "api", + "recurring", + "system" + ] + }, + "public.transaction_status": { + "name": "transaction_status", + "schema": "public", + "values": [ + "draft", + "pending", + "posted", + "void" + ] + }, + "public.transaction_type": { + "name": "transaction_type", + "schema": "public", + "values": [ + "expense", + "income", + "transfer", + "refund", + "adjustment", + "investment", + "asset_purchase", + "debt_payment", + "loan", + "equity" + ] + }, + "public.trust_level": { + "name": "trust_level", + "schema": "public", + "values": [ + "trusted", + "review" + ] + }, + "public.webhook_event_status": { + "name": "webhook_event_status", + "schema": "public", + "values": [ + "received", + "processed", + "ignored", + "failed", + "duplicate" + ] + }, + "public.workspace_kind": { + "name": "workspace_kind", + "schema": "public", + "values": [ + "personal", + "business" + ] + } + }, + "schemas": {}, + "views": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/drizzle/meta/_journal.json b/apps/api/drizzle/meta/_journal.json index 6cf817c..bd3cc9c 100644 --- a/apps/api/drizzle/meta/_journal.json +++ b/apps/api/drizzle/meta/_journal.json @@ -36,6 +36,13 @@ "when": 1790395330573, "tag": "0004_platform_audit", "breakpoints": true + }, + { + "idx": 5, + "version": "7", + "when": 1790899953420, + "tag": "0005_reminders_daily_last_3_days", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/api/src/db/schema/types.ts b/apps/api/src/db/schema/types.ts index bea953e..eef525c 100644 --- a/apps/api/src/db/schema/types.ts +++ b/apps/api/src/db/schema/types.ts @@ -4,7 +4,7 @@ import type { AgentMemoryItem } from "@expensewise/core"; // every figure that is summed or reported lives in a typed column instead. export type WorkspaceSettings = { - /** Days before a due date to remind, e.g. [30, 14, 7, 3, 1, 0]. */ + /** Days before a due date to remind, e.g. [2, 1, 0]. */ reminderOffsets?: number[]; /** Posted amounts at or above this (base currency, minor units) need review. */ reviewThreshold?: number | null; diff --git a/apps/api/src/modules/business/payroll.service.ts b/apps/api/src/modules/business/payroll.service.ts index b8e0f9e..c9c3079 100644 --- a/apps/api/src/modules/business/payroll.service.ts +++ b/apps/api/src/modules/business/payroll.service.ts @@ -69,8 +69,15 @@ export class PayrollService { async listEmployees(ctx: WorkspaceContext, raw: z.input = {}) { assertBusiness(ctx); const query = employeeQuery.parse(raw); + if (query.projectId) await assertInWorkspace(db, projects, ctx.workspaceId, [query.projectId], "Project"); const rows = await this.employeeSelect() - .where(and(eq(employees.workspaceId, ctx.workspaceId), query.status === "all" ? undefined : eq(employees.status, query.status))) + .where( + and( + eq(employees.workspaceId, ctx.workspaceId), + query.status === "all" ? undefined : eq(employees.status, query.status), + query.projectId ? eq(employees.defaultProjectId, query.projectId) : undefined, + ), + ) .orderBy(asc(employees.status), asc(employees.name)); const items = rows.map((row) => ({ ...row.employee, projectName: row.projectName, accountName: row.accountName, counterpartyName: row.counterpartyName })); const active = items.filter((item) => item.status === "active"); diff --git a/apps/api/src/modules/business/project-finance.service.ts b/apps/api/src/modules/business/project-finance.service.ts index a28ee6a..ebf2b07 100644 --- a/apps/api/src/modules/business/project-finance.service.ts +++ b/apps/api/src/modules/business/project-finance.service.ts @@ -125,6 +125,30 @@ export class ProjectFinanceService { return rows.map((row) => ({ ...row, total: Number(row.total) })); } + /** One project's revenue per month and category within the range, refunds paid out netted. */ + private async revenueMonths(ctx: WorkspaceContext, range: { from: Day | null; to: Day }, projectId: string) { + const month = sql`to_char(${transactions.date}, 'YYYY-MM')`; + const rows = await db + .select({ + month, + categoryId: transactions.categoryId, + type: transactions.type, + direction: transactions.direction, + total: sql`coalesce(sum(${transactions.baseAmount}), 0)`, + }) + .from(transactions) + .where( + this.posted(ctx, [ + inArray(transactions.type, ["income", "refund"]), + eq(transactions.projectId, projectId), + range.from ? gte(transactions.date, range.from) : undefined, + lte(transactions.date, range.to), + ]), + ) + .groupBy(month, transactions.categoryId, transactions.type, transactions.direction); + return rows.map((row) => ({ ...row, total: Number(row.total) })); + } + /** Revenue and cost per month for the last 12 months (this month included). */ private async monthly(ctx: WorkspaceContext, projectId?: string) { const day = todayFor(ctx); @@ -261,7 +285,7 @@ export class ProjectFinanceService { const range = resolveRange(ctx, financeRangeQuery.parse(raw), "lifetime"); const day = todayFor(ctx); const lifetimeRange = { from: null, to: day }; - const [flows, lifetime, series, first, recurring, byId, receivableViews, payableViews, vendors] = await Promise.all([ + const [flows, lifetime, series, first, recurring, byId, receivableViews, payableViews, vendors, revenueRows] = await Promise.all([ this.flows(ctx, range, projectId), this.flows(ctx, lifetimeRange, projectId, false), this.monthly(ctx, projectId), @@ -271,6 +295,7 @@ export class ProjectFinanceService { this.receivables.find(ctx, { projectId }), this.liabilities.find(ctx, { kinds: PAYABLE_KINDS, projectId }), this.topVendors(ctx, range, projectId), + this.revenueMonths(ctx, range, projectId), ]); const drillRange = { from: range.from, to: range.to }; @@ -298,6 +323,48 @@ export class ProjectFinanceService { }; }) .sort((a, b) => b.amount - a.amount); + // Revenue by category (net of refunds paid out). + const byRevenueCategory = new Map(); + for (const row of flows) { + const value = row.type === "income" ? row.total : row.type === "refund" && row.direction === "out" ? -row.total : 0; + if (value) byRevenueCategory.set(row.categoryId, (byRevenueCategory.get(row.categoryId) ?? 0) + value); + } + const revenueByCategory = [...byRevenueCategory.entries()] + .map(([categoryId, amount]) => ({ + categoryId, + name: (categoryId ? byId.get(categoryId)?.name : undefined) ?? "Uncategorized", + amount, + share: share(amount, revenue), + drill: txDrill(drillRange, ["income", "refund"], { projectId, categoryId }), + })) + .sort((a, b) => b.amount - a.amount); + // Revenue per profit month (newest first), each with its categories. + const revenueMonthMap = new Map>(); + for (const row of revenueRows) { + const value = row.type === "income" ? row.total : row.direction === "out" ? -row.total : 0; + if (!value) continue; + const categoriesInMonth = revenueMonthMap.get(row.month) ?? new Map(); + categoriesInMonth.set(row.categoryId, (categoriesInMonth.get(row.categoryId) ?? 0) + value); + revenueMonthMap.set(row.month, categoriesInMonth); + } + const revenueByMonth = [...revenueMonthMap.entries()] + .sort(([a], [b]) => b.localeCompare(a)) + .map(([month, categoriesInMonth]) => { + const monthRange = { from: `${month}-01`, to: endOfMonth(`${month}-01`) }; + return { + month, + amount: [...categoriesInMonth.values()].reduce((acc, value) => acc + value, 0), + drill: txDrill(monthRange, ["income", "refund"], { projectId }), + categories: [...categoriesInMonth.entries()] + .map(([categoryId, amount]) => ({ + categoryId, + name: (categoryId ? byId.get(categoryId)?.name : undefined) ?? "Uncategorized", + amount, + drill: txDrill(monthRange, ["income", "refund"], { projectId, categoryId }), + })) + .sort((a, b) => b.amount - a.amount), + }; + }); const costByGroup = COST_GROUPS.map((entry) => { const members = costByCategory.filter((row) => row.group === entry.group); const amount = members.reduce((acc, row) => acc + row.amount, 0); @@ -380,6 +447,8 @@ export class ProjectFinanceService { ownerDrawings: figure(drawings, txDrill(drillRange, ["equity"], { projectId })), costByGroup, costByCategory, + revenueByCategory, + revenueByMonth, topVendors: vendors, monthly, burn: { diff --git a/apps/api/src/modules/workspaces/provisioning.ts b/apps/api/src/modules/workspaces/provisioning.ts index b216b41..8655e2c 100644 --- a/apps/api/src/modules/workspaces/provisioning.ts +++ b/apps/api/src/modules/workspaces/provisioning.ts @@ -1,4 +1,4 @@ -import { type DefaultCategory, defaultCategories, SEED_RATES_TO_BDT, today, type WorkspaceKind } from "@expensewise/core"; +import { DEFAULT_REMINDER_OFFSETS, type DefaultCategory, defaultCategories, SEED_RATES_TO_BDT, today, type WorkspaceKind } from "@expensewise/core"; import { count, eq, inArray } from "drizzle-orm"; import { db, type Executor } from "../../db/index.js"; import { categories, exchangeRates, financialAccounts, projects, userSettings, users, workspaceMembers, workspaces } from "../../db/schema/index.js"; @@ -59,7 +59,7 @@ export async function createWorkspace(exec: Executor, ownerId: string, input: Ne baseCurrency, timezone: input.timezone ?? "Asia/Dhaka", fiscalYearStartMonth: input.fiscalYearStartMonth ?? (input.kind === "business" ? 7 : 1), - settings: { reminderOffsets: [30, 14, 7, 3, 1, 0], aiEnabled: true, autoPostHighConfidence: false }, + settings: { reminderOffsets: [...DEFAULT_REMINDER_OFFSETS], aiEnabled: true, autoPostHighConfidence: false }, }) .returning(); if (!workspace) throw new Error("Workspace was not created"); diff --git a/apps/api/tests/integration/planning.test.ts b/apps/api/tests/integration/planning.test.ts index d07a358..dd48b5a 100644 --- a/apps/api/tests/integration/planning.test.ts +++ b/apps/api/tests/integration/planning.test.ts @@ -90,6 +90,9 @@ const monthly = (overrides: Record = {}) => ({ ...overrides, }); +/** A longer reminder list than the default, to exercise early reminders and once-per-offset dedupe. */ +const LONG_REMINDERS = [30, 14, 7, 3, 1, 0]; + describe("subscriptions", () => { it("links the purchase of an annual plan instead of recording it twice", async () => { const { transaction: purchase } = await transactions.create(user.personal, { @@ -318,7 +321,7 @@ describe("subscriptions", () => { it("cancels, keeps the history and only sends the access-ends notice", async () => { const { subscription, commitment } = await subscriptions.create( user.personal, - monthly({ nextRenewalDate: addDays(T, 20), startDate: addDays(T, -10), expiryDate: addDays(T, 20) }), + monthly({ nextRenewalDate: addDays(T, 20), startDate: addDays(T, -10), expiryDate: addDays(T, 20), reminderOffsets: LONG_REMINDERS }), ); const cancelled = await subscriptions.cancel(user.personal, subscription.id, { reason: "Too expensive" }); expect(cancelled).toMatchObject({ @@ -699,6 +702,7 @@ describe("reminders", () => { startDate: T, nextRenewalDate: addDays(T, 30), accountId: card, + reminderOffsets: LONG_REMINDERS, }); const manual = await subscriptions.create(user.personal, { provider: "Namecheap", @@ -710,6 +714,7 @@ describe("reminders", () => { nextRenewalDate: addDays(T, 7), expiryDate: addDays(T, 7), autoRenew: false, + reminderOffsets: LONG_REMINDERS, }); const deadline = await subscriptions.create(user.personal, { provider: "Gym", @@ -719,6 +724,7 @@ describe("reminders", () => { startDate: T, nextRenewalDate: addDays(T, 10), cancellationDeadline: addDays(T, 3), + reminderOffsets: LONG_REMINDERS, }); const first = await reminders.scan(user.personal, T); @@ -758,6 +764,17 @@ describe("reminders", () => { expect((await subscriptions.get(user.personal, auto.subscription.id)).status).toBe("renewal_due"); }); + it("by default reminds two days before, the day before and on the day", async () => { + const sub = await subscriptions.create(user.personal, monthly({ nextRenewalDate: addDays(T, 10), startDate: T })); + for (let day = 0; day <= 10; day++) await reminders.scan(user.personal, addDays(T, day)); + const sent = (await sentFor(sub.subscription.id)).filter((n) => n.kind === "renewal"); + expect(sent.map((n) => n.title)).toEqual([ + "Netflix Standard renews in 2 days", + "Netflix Standard renewal is tomorrow", + "Netflix Standard renewal is due today", + ]); + }); + it("flags a payment that was due and never recorded, once", async () => { const internet = await commitmentsService.create(user.personal, { kind: "utility", diff --git a/apps/web/src/app/(app)/business/projects/[id]/page.tsx b/apps/web/src/app/(app)/business/projects/[id]/page.tsx index 981bb1d..0168cc5 100644 --- a/apps/web/src/app/(app)/business/projects/[id]/page.tsx +++ b/apps/web/src/app/(app)/business/projects/[id]/page.tsx @@ -2,19 +2,29 @@ import type { Metadata } from "next"; import { notFound } from "next/navigation"; import { PageShell } from "@/components/app/page-shell"; import { presetFrom } from "@/components/business/presets"; -import { ProjectProfileView } from "@/components/business/project-profile"; +import { ProjectProfileView, type ProjectTab } from "@/components/business/project-profile"; import { api, apiOrNull } from "@/lib/api/server"; import type { Project } from "@/lib/api/types"; -import type { ProjectProfile } from "@/lib/api/types/business"; +import type { EmployeeList, ProjectProfile } from "@/lib/api/types/business"; + +const TABS: ProjectTab[] = ["overview", "revenue", "cost", "payroll"]; export const metadata: Metadata = { title: "Project" }; -export default async function ProjectPage({ params, searchParams }: { params: Promise<{ id: string }>; searchParams: Promise<{ preset?: string }> }) { - const [{ id }, { preset: raw }] = await Promise.all([params, searchParams]); +export default async function ProjectPage({ + params, + searchParams, +}: { + params: Promise<{ id: string }>; + searchParams: Promise<{ preset?: string; tab?: string }>; +}) { + const [{ id }, { preset: raw, tab: rawTab }] = await Promise.all([params, searchParams]); const preset = presetFrom(raw, "all_time"); - const [profile, projects] = await Promise.all([ + const tab: ProjectTab = TABS.find((t) => t === rawTab) ?? "overview"; + const [profile, projects, employees] = await Promise.all([ apiOrNull(`/projects/${id}/finance`, { query: { preset } }), api("/projects", { query: { includeArchived: true } }), + tab === "payroll" ? apiOrNull("/payroll/employees", { query: { projectId: id } }) : null, ]); if (!profile) notFound(); return ( @@ -24,7 +34,7 @@ export default async function ProjectPage({ params, searchParams }: { params: Pr backHref="/business/projects" width="wide" > - p.id === id) ?? null} preset={preset} /> + p.id === id) ?? null} preset={preset} tab={tab} employees={employees} /> ); } diff --git a/apps/web/src/components/app/nav.ts b/apps/web/src/components/app/nav.ts index 1301fdc..2c1e4a9 100644 --- a/apps/web/src/components/app/nav.ts +++ b/apps/web/src/components/app/nav.ts @@ -26,7 +26,6 @@ import { Scale, Target, Upload, - Users, Wallet, } from "lucide-react"; @@ -99,7 +98,6 @@ export const SECTIONS: Array<{ id: string; title: string; tabs: SectionTab[]; se tabs: [ { title: "Projects", href: "/business/projects", icon: FolderKanban }, { title: "Revenue", href: "/business/revenue", icon: BadgeDollarSign }, - { title: "Payroll", href: "/business/payroll", icon: Users }, ], }, { diff --git a/apps/web/src/components/app/transaction-form.tsx b/apps/web/src/components/app/transaction-form.tsx index 9021be1..07b511e 100644 --- a/apps/web/src/components/app/transaction-form.tsx +++ b/apps/web/src/components/app/transaction-form.tsx @@ -1,6 +1,17 @@ "use client"; -import { COMMON_CURRENCIES, currencyDecimals, minorToInput, parseMoneyInput, type TransactionType, TYPE_LABELS, TYPE_RULES, today } from "@expensewise/core"; +import { + COMMON_CURRENCIES, + currencyDecimals, + endOfMonth, + minorToInput, + monthKey, + parseMoneyInput, + type TransactionType, + TYPE_LABELS, + TYPE_RULES, + today, +} from "@expensewise/core"; import { useRouter } from "next/navigation"; import { type FormEvent, useEffect, useId, useMemo, useRef, useState } from "react"; import { useApp } from "@/components/app/app-context"; @@ -14,11 +25,14 @@ import { Textarea } from "@/components/ui/textarea"; import { clientApi, errorMessage } from "@/lib/api/client"; import type { Account, Category, Project, Transaction, TransactionDetail } from "@/lib/api/types"; import { cn } from "@/lib/cn"; +import { formatMonth } from "@/lib/format-client"; import { toast } from "@/lib/toast"; import { invalidateApiCache, useApi } from "@/lib/use-api"; const NONE = "__none__"; const PRIMARY: TransactionType[] = ["expense", "income", "transfer"]; +/** Types that cannot be saved without an invoice, receipt or proof of payment. */ +const NEEDS_PROOF: TransactionType[] = ["income", "expense"]; const MORE: TransactionType[] = ["refund", "adjustment", "investment", "asset_purchase", "debt_payment", "loan", "equity"]; const DIRECTION_LABELS: Partial> = { @@ -87,6 +101,15 @@ function initialState(type: TransactionType, baseCurrency: string, timezone: str }; } +/** + * Income is entered per profit month: it is booked on the month's last day, or + * today while that month is still running, so monthly reports count it there. + */ +function dayInMonth(month: string, timezone: string): string { + const now = today(timezone); + return month === monthKey(now) ? now : endOfMonth(`${month}-01`); +} + /** * Records or edits any kind of transaction. Only the fields the type needs * are shown; amounts are typed in major units and sent as minor units. @@ -178,6 +201,12 @@ export function TransactionFormDialog({ if (!amount) return setError(`Enter the amount in ${form.currency}, e.g. 1,500 or 1500.50`); if (!form.accountId) return setError("Choose the account the money moved through"); if (form.type === "transfer" && !form.toAccountId) return setError("Choose the account the money went to"); + // Income and expenses need their invoice, receipt or proof of payment. Edits wait until the saved files have loaded. + const attachmentsKnown = !transaction || Boolean(savedAttachments || detail.data || attachmentsTouched); + if (NEEDS_PROOF.includes(form.type) && attachmentsKnown && attachments.length === 0) + return setError( + `Attach the ${form.type === "income" ? "invoice or proof of payment" : "invoice or receipt"}. If a file is still uploading, wait for it to finish.`, + ); const accountAmount = needsAccountAmount && form.accountAmount ? parseMoneyInput(form.accountAmount, account?.currency ?? form.currency) : null; const toAccountAmount = needsToAmount && form.toAccountAmount ? parseMoneyInput(form.toAccountAmount, toAccount?.currency ?? form.currency) : null; @@ -376,10 +405,23 @@ export function TransactionFormDialog({ )}
-
- - set("date", e.target.value)} /> -
+ {form.type === "income" ? ( +
+ + e.target.value && set("date", dayInMonth(e.target.value, workspace.timezone))} + /> +
+ ) : ( +
+ + set("date", e.target.value)} /> +
+ )} {form.type !== "transfer" && (
@@ -392,6 +434,12 @@ export function TransactionFormDialog({
)}
+ {form.type === "income" && ( +

+ Counts toward {formatMonth(monthKey(form.date))} in profit and project reports. + {transaction ? "" : " The day you entered it is kept as the recorded date."} +

+ )} {usesCategory && (
@@ -448,7 +496,7 @@ export function TransactionFormDialog({ +
+ Salaries post as Payroll expenses on this project when you post the month's payroll run. Don't also enter them by hand. + +
+ +
+ ); +} + +function EmployeesTab({ employees, projectId }: { employees: EmployeeList; projectId?: string }) { const { money, canWrite } = useApp(); const [editing, setEditing] = useState(null); const [creating, setCreating] = useState(false); @@ -88,8 +103,12 @@ function EmployeesTab({ employees }: { employees: EmployeeList }) { <> setCreating(true)}> @@ -98,7 +117,7 @@ function EmployeesTab({ employees }: { employees: EmployeeList }) { ) : undefined } /> - + ); } @@ -133,7 +152,7 @@ function EmployeesTab({ employees }: { employees: EmployeeList }) { Employee Monthly salary Pay day - Project + {!projectId && Project} Paid from Status {canWrite && } @@ -150,7 +169,7 @@ function EmployeesTab({ employees }: { employees: EmployeeList }) { {money(e.salary, e.currency)} {ordinal(e.payDay)} - {e.projectName ?? "—"} + {!projectId && {e.projectName ?? "—"}} {e.accountName ?? Not set} @@ -167,7 +186,7 @@ function EmployeesTab({ employees }: { employees: EmployeeList }) { - + !open && setEditing(null)} employee={editing} /> ); @@ -178,7 +197,18 @@ function ordinal(day: number) { return `${day}${suffix} of the month`; } -export function EmployeeFormDialog({ open, onOpenChange, employee }: { open: boolean; onOpenChange: (open: boolean) => void; employee?: Employee | null }) { +export function EmployeeFormDialog({ + open, + onOpenChange, + employee, + defaultProjectId, +}: { + open: boolean; + onOpenChange: (open: boolean) => void; + employee?: Employee | null; + /** A new employee starts on this project. */ + defaultProjectId?: string; +}) { const id = useId(); const refresh = useRefresh(); const { workspace } = useApp(); @@ -208,14 +238,14 @@ export function EmployeeFormDialog({ open, onOpenChange, employee }: { open: boo setSalary(employee ? minorToInput(employee.salary, employee.currency) : ""); setCurrency(employee?.currency ?? workspace.baseCurrency); setPayDay(String(employee?.payDay ?? 1)); - setProjectId(employee?.defaultProjectId ?? null); + setProjectId(employee ? employee.defaultProjectId : (defaultProjectId ?? null)); setAccountId(employee?.accountId ?? null); setStartDate(employee?.startDate ?? ""); setEndDate(employee?.endDate ?? ""); setStatus(employee?.status ?? "active"); setNotes(employee?.notes ?? ""); setCommitment(false); - }, [open, employee, workspace.baseCurrency]); + }, [open, employee, defaultProjectId, workspace.baseCurrency]); const submit = async (event: FormEvent) => { event.preventDefault(); diff --git a/apps/web/src/components/business/project-profile.tsx b/apps/web/src/components/business/project-profile.tsx index 8dbf49d..f1382ee 100644 --- a/apps/web/src/components/business/project-profile.tsx +++ b/apps/web/src/components/business/project-profile.tsx @@ -9,12 +9,14 @@ import { EmptyNote, ProgressBar, Section, StatCard, StatusBadge } from "@/compon import { BarsChart, SERIES } from "@/components/charts/charts"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; +import { ParamTabs } from "@/components/wealth/shared"; import type { Project } from "@/lib/api/types"; -import type { ProjectProfile, RecurringSummary } from "@/lib/api/types/business"; +import type { EmployeeList, ProjectProfile, RecurringSummary } from "@/lib/api/types/business"; import { cn } from "@/lib/cn"; import { percentText } from "@/lib/format"; import { formatMonth } from "@/lib/format-client"; import { drillHref, groupDrillHref } from "./drill"; +import { ProjectPayroll } from "./payroll"; import { ProjectFormDialog } from "./projects"; import { RangeSelect } from "./range-select"; @@ -55,7 +57,65 @@ function RecurringList({ summary, empty }: { summary: RecurringSummary; empty: s ); } -export function ProjectProfileView({ profile, project, preset }: { profile: ProjectProfile; project: Project | null; preset: string }) { +export type ProjectTab = "overview" | "revenue" | "cost" | "payroll"; + +type Actual = ProjectProfile["actual"]; + +/** Categories with their amount and share, each opening the transactions behind it. */ +function CategoryList({ rows, tone, empty }: { rows: Actual["revenueByCategory"]; tone?: "good"; empty: string }) { + const { money } = useApp(); + if (!rows.length) return {empty}; + return ( +
    + {rows.map((c) => ( +
  • + + + {c.name} + {money(c.amount)} + + + + {percentText(c.share)} + + +
  • + ))} +
+ ); +} + +function OpenBalance({ kind, actual }: { kind: "receivables" | "payables"; actual: Actual }) { + const { money } = useApp(); + const b = actual[kind]; + const Icon = kind === "receivables" ? HandCoins : Receipt; + return ( + +

+ {kind === "receivables" ? "Owed to it" : "It owes"} +

+

{money(b.outstanding)}

+

+ {b.overdueCount ? `${money(b.overdue)} overdue` : `${b.count} open`} +

+ + ); +} + +export function ProjectProfileView({ + profile, + project, + preset, + tab, + employees, +}: { + profile: ProjectProfile; + project: Project | null; + preset: string; + tab: ProjectTab; + /** Loaded only on the payroll tab. */ + employees: EmployeeList | null; +}) { const { money, locale, canWrite } = useApp(); const [editing, setEditing] = useState(false); const { actual, estimated } = profile; @@ -63,9 +123,27 @@ export function ProjectProfileView({ profile, project, preset }: { profile: Proj const net = actual.netContribution.amount; const hasActivity = actual.revenue.amount !== 0 || actual.cost.amount !== 0 || actual.capitalInvested.amount !== 0 || actual.monthly.some((m) => m.revenue || m.cost); + const tabHref = (next: ProjectTab) => { + const query = new URLSearchParams(); + if (next !== "overview") query.set("tab", next); + if (preset !== "all_time") query.set("preset", preset); + return `/business/projects/${profile.project.id}${query.size ? `?${query}` : ""}`; + }; return (
+ +
@@ -93,246 +171,296 @@ export function ProjectProfileView({ profile, project, preset }: { profile: Proj
)} - -
- - - - -
- - {!hasActivity ? ( - - Nothing is tagged with this project yet. Choose it as the project on income and expenses, or set it as an employee's default project. - - ) : ( - <> -
- ({ - label: m.month, - revenue: m.revenue, - cost: m.cost, - }))} - series={[ - { key: "revenue", label: "Revenue", color: SERIES.primary }, - { key: "cost", label: "Cost", color: SERIES.secondary }, - ]} - format={(v) => money(v)} - axisFormat={compact} - tickFormat={(label) => formatMonth(label, "en-GB", true).split(" ")[0] ?? label} - labelFormat={(label) => formatMonth(label)} - /> -
- -
-
- {actual.costByGroup.length ? ( -
    - {actual.costByGroup.map((g) => ( -
  • - - - {g.label} - {money(g.amount)} - - - - {percentText(g.share)} - - -
  • - ))} -
- ) : ( - No costs in this range. - )} + {tab === "revenue" && ( + <> +
+ + + +
+
+
+
+
-
- {actual.costByCategory.length ? ( +
+ {actual.revenueByMonth.length ? (
    - {actual.costByCategory.map((c) => ( -
  • - - {c.name} - - {money(c.amount)} {percentText(c.share)} - + {actual.revenueByMonth.map((m) => ( +
  • + + {formatMonth(m.month)} + {money(m.amount)} +
      + {m.categories.map((c) => ( +
    • + + {c.name} + {money(c.amount)} + +
    • + ))} +
  • ))}
) : ( - No costs in this range. + No revenue in this range. )}
- - )} +
+
+ +
+
+ +
+
+
+ + )} -
-
formatMonth(m, "en-GB", true)).join(", ")}` : "Needs a complete month" - } - > -
- -

Spending a month

-

{money(actual.burn.monthlyBurn.amount)}

- - -

Net burn a month

-

- {actual.burn.netBurn.amount < 0 ? `${money(-actual.burn.netBurn.amount)} gained` : money(actual.burn.netBurn.amount)} -

- + {tab === "cost" && ( + <> +
+ + + +
+
+
+ +
+
+ {actual.costByGroup.length ? ( +
    + {actual.costByGroup.map((g) => ( +
  • + + {g.label} + + {money(g.amount)} {percentText(g.share)} + + +
  • + ))} +
+ ) : ( + No costs in this range. + )} +
+
+
+
+ {actual.topVendors.length ? ( +
    + {actual.topVendors.map((v) => ( +
  • + + + {v.name} + {v.count} payments + + {money(v.amount)} + +
  • + ))} +
+ ) : ( + No payments in this range. + )} +
+
+ +
+
+ +
+
+ + )} + + {tab === "payroll" && employees && } + + {tab === "overview" && ( + <> + +
+ + + +
-
-
- {actual.budget ? ( -
-
- - {money(actual.budget.spent.amount)} - - of {money(actual.budget.amount)} -
- 100 ? "danger" : (actual.budget.utilization ?? 0) > 80 ? "warn" : "good"} - /> -

- {percentText(actual.budget.utilization)} used ·{" "} - {(actual.budget.remaining ?? 0) >= 0 ? `${money(actual.budget.remaining)} left` : `${money(-(actual.budget.remaining ?? 0))} over`} -

-
- ) : ( - setEditing(true)}> - Set a budget - - ) : undefined - } - > - No budget set. + + {!hasActivity ? ( + + Nothing is tagged with this project yet. Choose it as the project on income and expenses, or set it as an employee's default project. + ) : ( +
+ ({ + label: m.month, + revenue: m.revenue, + cost: m.cost, + }))} + series={[ + { key: "revenue", label: "Revenue", color: SERIES.primary }, + { key: "cost", label: "Cost", color: SERIES.secondary }, + ]} + format={(v) => money(v)} + axisFormat={compact} + tickFormat={(label) => formatMonth(label, "en-GB", true).split(" ")[0] ?? label} + labelFormat={(label) => formatMonth(label)} + /> +
)} -
-
-
- -

- Owed to it -

-

{money(actual.receivables.outstanding)}

-

- {actual.receivables.overdueCount ? `${money(actual.receivables.overdue)} overdue` : `${actual.receivables.count} open`} -

- - -

- It owes -

-

{money(actual.payables.outstanding)}

-

- {actual.payables.overdueCount ? `${money(actual.payables.overdue)} overdue` : `${actual.payables.count} open`} -

- -
-
-
-
- {actual.topVendors.length ? ( -
    - {actual.topVendors.map((v) => ( -
  • - - - {v.name} - {v.count} payments - - {money(v.amount)} +
    +
    formatMonth(m, "en-GB", true)).join(", ")}` : "Needs a complete month" + } + > +
    + +

    Spending a month

    +

    {money(actual.burn.monthlyBurn.amount)}

    -
  • - ))} -
- ) : ( - No payments in this range. - )} -
- + +

Net burn a month

+

+ {actual.burn.netBurn.amount < 0 ? `${money(-actual.burn.netBurn.amount)} gained` : money(actual.burn.netBurn.amount)} +

+ +
+ +
+ {actual.budget ? ( +
+
+ + {money(actual.budget.spent.amount)} + + of {money(actual.budget.amount)} +
+ 100 ? "danger" : (actual.budget.utilization ?? 0) > 80 ? "warn" : "good"} + /> +

+ {percentText(actual.budget.utilization)} used ·{" "} + {(actual.budget.remaining ?? 0) >= 0 ? `${money(actual.budget.remaining)} left` : `${money(-(actual.budget.remaining ?? 0))} over`} +

+
+ ) : ( + setEditing(true)}> + Set a budget + + ) : undefined + } + > + No budget set. + + )} +
+
+
+ + +
+
+
+ - -
-
- {estimated.runwayMonths !== null ? ( -
-

- {estimated.runwayMonths} months -

-

{estimated.runwayBasis}

-
- ) : ( -

{estimated.runwayUnavailableReason ?? "Not enough information for an estimate."}

- )} -
-
- -
-
- -
-
-
+ +
+ {estimated.runwayMonths !== null ? ( +
+

+ {estimated.runwayMonths} months +

+

{estimated.runwayBasis}

+
+ ) : ( +

{estimated.runwayUnavailableReason ?? "Not enough information for an estimate."}

+ )} +
+
-
- - - -
+
+ + + +
+ + )} {project && }
diff --git a/apps/web/src/components/business/projects.tsx b/apps/web/src/components/business/projects.tsx index 6163fc4..4935613 100644 --- a/apps/web/src/components/business/projects.tsx +++ b/apps/web/src/components/business/projects.tsx @@ -1,7 +1,7 @@ "use client"; import { minorToInput } from "@expensewise/core"; -import { ArrowDownLeft, ArrowUpRight, Flame, FolderKanban, Hourglass, Plus, Repeat, TrendingUp } from "lucide-react"; +import { ArrowDownLeft, ArrowUpRight, ChevronRight, Flame, FolderKanban, Hourglass, Plus, Repeat, TrendingUp } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { type FormEvent, useEffect, useId, useState } from "react"; @@ -46,41 +46,33 @@ function ProjectCard({ row }: { row: ProjectOverviewRow }) { const net = actual.netContribution; const utilization = actual.budget?.utilization ?? null; return ( -
+
- +

{project.name}

{[project.code, project.isDefault ? "Default project" : null].filter(Boolean).join(" · ") || " "}

- +
{project.status !== "active" && }

Revenue

- +

Cost

- +

Net

{money(net, undefined, { signed: true })}
-
- - {money(actual.monthlyBurn)}/mo burn - - {actual.capitalInvested.amount > 0 && ( - - {money(actual.capitalInvested.amount)} capital in - - )} - {actual.receivablesOutstanding > 0 && {money(actual.receivablesOutstanding)} owed to it} -
{actual.budget && (
@@ -90,13 +82,21 @@ function ProjectCard({ row }: { row: ProjectOverviewRow }) { 100 ? "danger" : (utilization ?? 0) > 80 ? "warn" : "good"} />
)} - {estimated.runwayMonths !== null && ( -

- About {estimated.runwayMonths} months of budget left at this burn{" "} - estimate -

- )} -
+
+ + {money(actual.monthlyBurn)}/mo burn + {estimated.runwayMonths !== null && ( + <> + {" · "} + ~{estimated.runwayMonths} mo left + + )} + + + Open + +
+ ); } diff --git a/apps/web/src/components/planning/goal-form.tsx b/apps/web/src/components/planning/goal-form.tsx index 23bb60e..c78895f 100644 --- a/apps/web/src/components/planning/goal-form.tsx +++ b/apps/web/src/components/planning/goal-form.tsx @@ -98,6 +98,9 @@ export function GoalFormDialog({ open, onOpenChange, goal, defaultKind = "saving setError(null); const targetAmount = parseMoneyInput(target, currency); if (!targetAmount) return setError(dream ? "Enter the price of what you want" : "Enter the target amount"); + // An edit waits until the saved picture has loaded. + const pictureKnown = !goal?.imageFileId || pictureTouched || Boolean(savedPicture.data || savedPicture.error); + if (pictureKnown && !picture.length) return setError("Add a picture. If it is still uploading, wait for it to finish."); const plan = monthlyPlan ? parseMoneyInput(monthlyPlan, currency) : null; if (monthlyPlan && plan === null) return setError("Enter the monthly amount as a number"); const start = starting ? parseMoneyInput(starting, currency) : 0; @@ -249,7 +252,7 @@ export function GoalFormDialog({ open, onOpenChange, goal, defaultKind = "saving max={1} kind="other" imagesOnly - label={dream ? "Picture" : "Picture (optional)"} + label="Picture (required)" hint={dream ? "A photo of what you're saving for keeps it in sight." : null} disabled={Boolean(goal?.imageFileId && !savedPicture.data && !savedPicture.error && !pictureTouched)} /> diff --git a/apps/web/src/components/planning/payment-dialogs.tsx b/apps/web/src/components/planning/payment-dialogs.tsx index ed73267..2ca9f8a 100644 --- a/apps/web/src/components/planning/payment-dialogs.tsx +++ b/apps/web/src/components/planning/payment-dialogs.tsx @@ -89,6 +89,11 @@ export function MarkPaidDialog({ target, onClose, onDone }: { target: PayTarget if (!target) return; setError(null); if (!extra.existingTransactionId && (parsed === null || parsed <= 0)) return setError("Enter the amount paid, e.g. 1,850"); + // Linking an existing transaction records nothing new, so only a new one needs its file. + if (!extra.existingTransactionId && !attachments.length) + return setError( + `Attach the ${target.direction === "in" ? "proof of payment" : "receipt or invoice"}. If a file is still uploading, wait for it to finish.`, + ); setBusy(key); try { const body: MarkPaidBody = { @@ -248,8 +253,8 @@ export function MarkPaidDialog({ target, onClose, onDone }: { target: PayTarget diff --git a/apps/web/src/components/planning/shared.tsx b/apps/web/src/components/planning/shared.tsx index 1b05ed9..f783835 100644 --- a/apps/web/src/components/planning/shared.tsx +++ b/apps/web/src/components/planning/shared.tsx @@ -262,7 +262,7 @@ export function ReminderOffsetsField({ const [custom, setCustom] = useState(""); const own = value !== null; const chosen = value ?? workspaceDefault; - const presets = [...new Set([60, 30, 14, 7, 3, 1, 0, ...chosen])].sort((a, b) => b - a); + const presets = [...new Set([60, 30, 14, 7, 3, 2, 1, 0, ...chosen])].sort((a, b) => b - a); const toggle = (offset: number) => { const next = chosen.includes(offset) ? chosen.filter((o) => o !== offset) : [...chosen, offset]; onChange(next.sort((a, b) => b - a)); diff --git a/apps/web/src/components/planning/subscription-detail.tsx b/apps/web/src/components/planning/subscription-detail.tsx index 86e9be6..383d088 100644 --- a/apps/web/src/components/planning/subscription-detail.tsx +++ b/apps/web/src/components/planning/subscription-detail.tsx @@ -1,12 +1,12 @@ "use client"; -import { formatDay, relativeDays, today } from "@expensewise/core"; +import { DEFAULT_REMINDER_OFFSETS, formatDay, relativeDays, today } from "@expensewise/core"; import { Ban, CalendarClock, CheckCircle2, MoreHorizontal, Paperclip, Pause, Pencil, Play, Receipt, Trash2, TrendingUp, Wallet } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useId, useState } from "react"; import { useApp } from "@/components/app/app-context"; -import { CategoryChip, EmptyNote, Facts, Section, StatCard, StatusBadge } from "@/components/app/blocks"; +import { CategoryChip, EmptyNote, Facts, Section, StatCard } from "@/components/app/blocks"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/menu"; @@ -20,6 +20,7 @@ import { ConfirmDialog, OccurrenceTable } from "./occurrence-history"; import { MarkPaidDialog, type PayTarget, SkipDialog, type SkipTarget, undoPayment } from "./payment-dialogs"; import { AutoRenewBadge, DueDate, Field, PriceChangeBadge, renewalStatement } from "./shared"; import { SubscriptionFormDialog } from "./subscription-form"; +import { StatusMenu } from "./subscription-status"; export function SubscriptionDetailView({ subscription: s }: { subscription: SubscriptionDetail }) { const { money, canWrite, workspace, isBusiness } = useApp(); @@ -97,7 +98,7 @@ export function SubscriptionDetailView({ subscription: s }: { subscription: Subs } }; - const reminders = s.reminderOffsets?.length ? s.reminderOffsets : (workspace.settings.reminderOffsets ?? [30, 14, 7, 3, 1, 0]); + const reminders = s.reminderOffsets?.length ? s.reminderOffsets : (workspace.settings.reminderOffsets ?? DEFAULT_REMINDER_OFFSETS); return (
@@ -106,7 +107,7 @@ export function SubscriptionDetailView({ subscription: s }: { subscription: Subs
- + {s.categoryName && }
diff --git a/apps/web/src/components/planning/subscription-form.tsx b/apps/web/src/components/planning/subscription-form.tsx index 67690f4..ee501b5 100644 --- a/apps/web/src/components/planning/subscription-form.tsx +++ b/apps/web/src/components/planning/subscription-form.tsx @@ -121,6 +121,9 @@ export function SubscriptionFormDialog({ open, onOpenChange, subscription, onSav if (open && !attachmentTouched && savedFile.data) setAttachments([savedFile.data]); }, [open, attachmentTouched, savedFile.data]); + // The saved file is still loading, so the attachment list is not known yet. + const savedFileLoading = Boolean(subscription?.attachmentFileId && !savedFile.data && !savedFile.error && !attachmentTouched); + const changeAttachments = (next: Attachment[]) => { setAttachments(next); setAttachmentTouched(true); @@ -144,6 +147,7 @@ export function SubscriptionFormDialog({ open, onOpenChange, subscription, onSav const amountMinor = parseMoneyInput(amount, currency); if (!amountMinor) return setError("Enter the renewal amount, e.g. 20 or 1,850"); if (!provider.trim()) return setError("Who is the subscription with?"); + if (!attachments.length && !savedFileLoading) return setError("Attach the invoice or receipt. If a file is still uploading, wait for it to finish."); if (!nextRenewalDate && !editing) return setError("When does it renew next?"); const count = Number(intervalCount); if (billingCycle === "custom" && (!Number.isInteger(count) || count < 1)) return setError("Enter how many days, weeks, months or years per cycle"); @@ -406,8 +410,8 @@ export function SubscriptionFormDialog({ open, onOpenChange, subscription, onSav value={attachments} onChange={changeAttachments} max={1} - label="Invoice or receipt" - disabled={Boolean(subscription?.attachmentFileId && !savedFile.data && !savedFile.error && !attachmentTouched)} + label="Invoice or receipt (required)" + disabled={savedFileLoading} hint={recordPurchase ? "Also attached to the purchase expense recorded below." : "The purchase invoice or the latest receipt."} /> diff --git a/apps/web/src/components/planning/subscription-status.tsx b/apps/web/src/components/planning/subscription-status.tsx new file mode 100644 index 0000000..141c465 --- /dev/null +++ b/apps/web/src/components/planning/subscription-status.tsx @@ -0,0 +1,160 @@ +"use client"; + +import type { SubscriptionStatus } from "@expensewise/core"; +import { Ban, Check, ChevronDown, Pause, Play } from "lucide-react"; +import { useRouter } from "next/navigation"; +import { useId, useState } from "react"; +import { useApp } from "@/components/app/app-context"; +import { Input } from "@/components/ui/input"; +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/menu"; +import { clientApi, errorMessage } from "@/lib/api/client"; +import { cn } from "@/lib/cn"; +import { toast } from "@/lib/toast"; +import { invalidateApiCache } from "@/lib/use-api"; +import { ConfirmDialog } from "./occurrence-history"; +import { Field } from "./shared"; + +export type Tone = "green" | "blue" | "amber" | "orange" | "red" | "gray"; + +export const TONES: Record = { + green: { pill: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-400", dot: "bg-emerald-500" }, + blue: { pill: "bg-sky-500/10 text-sky-700 dark:text-sky-400", dot: "bg-sky-500" }, + amber: { pill: "bg-amber-500/10 text-amber-700 dark:text-amber-400", dot: "bg-amber-500" }, + orange: { pill: "bg-orange-500/10 text-orange-700 dark:text-orange-400", dot: "bg-orange-500" }, + red: { pill: "bg-red-500/10 text-red-700 dark:text-red-400", dot: "bg-red-500" }, + gray: { pill: "bg-muted text-muted-foreground", dot: "bg-muted-foreground/60" }, +}; + +const STATUS_TONES: Record = { + active: "green", + renewed: "green", + trial: "blue", + renewal_due: "amber", + cancellation_pending: "orange", + cancelled: "gray", + paused: "gray", + expired: "red", +}; + +export function statusTone(status: SubscriptionStatus) { + return TONES[STATUS_TONES[status] ?? "gray"]; +} + +type StatusSubject = { + id: string; + name: string; + derivedStatus: SubscriptionStatus; + statusLabel: string; + expiryDate: string | null; + nextRenewalDate: string | null; +}; + +/** + * The subscription's status as a coloured pill. For people who can write it + * is also the place to change it: pause, resume, cancel or reactivate. + */ +export function StatusMenu({ subscription: s, today }: { subscription: StatusSubject; today: string }) { + const { canWrite } = useApp(); + const router = useRouter(); + const id = useId(); + const [cancelOpen, setCancelOpen] = useState(false); + const [effectiveDate, setEffectiveDate] = useState(s.expiryDate ?? s.nextRenewalDate ?? today); + const [reason, setReason] = useState(""); + const [busy, setBusy] = useState(false); + const tone = statusTone(s.derivedStatus); + + const stopped = s.derivedStatus === "cancelled" || s.derivedStatus === "cancellation_pending" || s.derivedStatus === "expired"; + const paused = s.derivedStatus === "paused"; + + const act = async (action: "pause" | "resume" | "cancel", message: string, body?: unknown) => { + setBusy(true); + try { + await clientApi(`/subscriptions/${s.id}/${action}`, { method: "POST", body }); + toast.success(message); + invalidateApiCache("/subscriptions"); + router.refresh(); + return true; + } catch (err) { + toast.error(errorMessage(err)); + return false; + } finally { + setBusy(false); + } + }; + + const cancel = async () => { + if (await act("cancel", "Subscription cancelled; the history is kept", { effectiveDate: effectiveDate || null, reason: reason.trim() || null })) { + setCancelOpen(false); + } + }; + + const pill = ( + <> + + {s.statusLabel} + + ); + const pillClass = cn("inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium whitespace-nowrap", tone.pill); + + if (!canWrite) return {pill}; + + return ( + <> + + e.stopPropagation()} + /> + } + > + {pill} + + + +

Change status

+ {paused || stopped ? ( + void act("resume", stopped ? "Reactivated" : "Active again; reminders are back")}> + {stopped ? "Reactivate" : "Active — resume"} + + ) : ( + + Active + + )} + {!stopped && !paused && ( + void act("pause", "Paused; reminders stop until you resume")}> + Pause — stop reminders for now + + )} + {!stopped && ( + setCancelOpen(true)}> + Cancel subscription… + + )} +
+
+ void cancel()} + > +
+ + setEffectiveDate(e.target.value)} /> + + + setReason(e.target.value)} placeholder="Optional" /> + +
+
+ + ); +} diff --git a/apps/web/src/components/planning/subscriptions-view.tsx b/apps/web/src/components/planning/subscriptions-view.tsx index 7afbbb2..dfc6686 100644 --- a/apps/web/src/components/planning/subscriptions-view.tsx +++ b/apps/web/src/components/planning/subscriptions-view.tsx @@ -1,32 +1,26 @@ "use client"; -import { SUBSCRIPTION_STATUS_LABELS, type SubscriptionStatus } from "@expensewise/core"; -import { AlertTriangle, CalendarClock, CalendarRange, CircleAlert, Plus, Repeat, Search, Wallet, X } from "lucide-react"; +import { formatDay, SUBSCRIPTION_STATUS_LABELS, type SubscriptionStatus } from "@expensewise/core"; +import { AlertTriangle, CalendarClock, CircleAlert, Plus, Repeat, Search, Wallet, X } from "lucide-react"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { useEffect, useState } from "react"; import { useApp } from "@/components/app/app-context"; -import { CategoryChip, EmptyNote, EmptyState, Pill, ProgressBar, Section, StatCard, StatusBadge } from "@/components/app/blocks"; +import { CategoryChip, EmptyNote, EmptyState, Pill, ProgressBar, Section, StatCard } from "@/components/app/blocks"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import type { SubscriptionAnalytics, SubscriptionList, SubscriptionView } from "@/lib/api/types/planning"; import { cn } from "@/lib/cn"; import { MarkPaidDialog, type PayTarget } from "./payment-dialogs"; -import { AutoRenewBadge, DueDate, NONE, OptionSelect, renewalStatement, useQueryNav } from "./shared"; -import { BILLING_LABELS, SubscriptionFormDialog } from "./subscription-form"; +import { NONE, OptionSelect, renewalStatement, useQueryNav } from "./shared"; +import { SubscriptionFormDialog } from "./subscription-form"; +import { StatusMenu, statusTone, TONES, type Tone } from "./subscription-status"; export type SubscriptionFilters = { q?: string; status?: string; billingCycle?: string; sort?: string }; -const SORTS = [ - { value: "renewal_asc", label: "Next renewal" }, - { value: "amount_desc", label: "Highest amount" }, - { value: "monthly_desc", label: "Highest monthly cost" }, - { value: "name_asc", label: "Name" }, -]; - const STATUS_FILTERS: Array<{ value: string; label: string }> = [ - { value: NONE, label: "All statuses" }, - { value: "trial,active,renewal_due,renewed", label: "Active" }, + { value: NONE, label: "All subscriptions" }, + { value: "trial,active,renewal_due,renewed", label: "Active only" }, ...(["renewal_due", "trial", "cancellation_pending", "cancelled", "expired", "paused"] as SubscriptionStatus[]).map((status) => ({ value: status, label: SUBSCRIPTION_STATUS_LABELS[status], @@ -120,48 +114,31 @@ export function SubscriptionsView({ return (
-
- +
- - @@ -182,23 +159,7 @@ export function SubscriptionsView({ value={filters.status ?? NONE} onChange={(v) => update({ status: v })} options={STATUS_FILTERS} - placeholder="All statuses" - /> - update({ billingCycle: v })} - options={[{ value: NONE, label: "Any billing cycle" }, ...Object.entries(BILLING_LABELS).map(([value, label]) => ({ value, label }))]} - placeholder="Any billing cycle" - /> - update({ sort: v === "renewal_asc" ? null : v })} - options={SORTS} - placeholder="Sort" + placeholder="All subscriptions" /> {filtered && (
{list.items.length === 0 ? ( }> Clear filters @@ -234,196 +188,206 @@ export function SubscriptionsView({ } /> ) : ( -
- - - - - - - - - - - - {list.items.map((subscription) => ( - - setPaying({ - occurrenceId: subscription.nextOccurrenceId as string, - name: subscription.name, - dueDate: subscription.nextRenewalDate as string, - amount: subscription.amount, - currency: subscription.currency, - accountId: subscription.accountId, - direction: "out", - renewal: true, - }) - : undefined - } - /> - ))} - -
SubscriptionStatusAmountNext renewalCancel by -
+
+
+ Subscription + Status + Next payment + Cost +
+
    + {list.items.map((subscription) => ( + + setPaying({ + occurrenceId: subscription.nextOccurrenceId as string, + name: subscription.name, + dueDate: subscription.nextRenewalDate as string, + amount: subscription.amount, + currency: subscription.currency, + accountId: subscription.accountId, + direction: "out", + renewal: true, + }) + : undefined + } + /> + ))} +
)} -
- ({ - key: g.categoryId ?? "none", - label: g.categoryName ?? "Uncategorized", - count: g.count, - monthly: g.monthly, - annual: g.annual, - }))} - /> - ({ - key: g.billingCycle, - label: BILLING_LABELS[g.billingCycle], - count: g.count, - monthly: g.monthly, - annual: g.annual, - href: `/subscriptions?billingCycle=${g.billingCycle}`, - }))} - /> - {isBusiness && ( - ({ - key: g.projectId ?? "none", - label: g.projectName ?? "No project", + ({ + key: g.categoryId ?? "none", + label: g.categoryName ?? "Uncategorized", count: g.count, monthly: g.monthly, annual: g.annual, - }))} - /> - )} -
+ })), + }, + ...(isBusiness + ? [ + { + key: "project", + label: "By project", + rows: analytics.byProject.map((g) => ({ + key: g.projectId ?? "none", + label: g.projectName ?? "No project", + count: g.count, + monthly: g.monthly, + annual: g.annual, + })), + }, + ] + : []), + ]} + /> setPaying(null)} />
); } +/** "in 31 days" as a chip that warms up as the day gets close. */ +function Countdown({ days }: { days: number }) { + const tone: Tone = days < 0 ? "red" : days <= 2 ? "red" : days <= 7 ? "amber" : "gray"; + const text = days < 0 ? `${-days}d overdue` : days === 0 ? "Today" : days === 1 ? "Tomorrow" : `in ${days} days`; + return {text}; +} + function SubscriptionRow({ subscription: s, today, onPay }: { subscription: SubscriptionView; today: string; onPay?: () => void }) { const { money } = useApp(); - const router = useRouter(); const statement = renewalStatement(s, money); - const open = () => router.push(`/subscriptions/${s.id}`); + const ended = s.derivedStatus === "cancellation_pending" || s.derivedStatus === "cancelled" || s.derivedStatus === "expired" || s.derivedStatus === "paused"; + const tone = statusTone(s.derivedStatus); + const next = ended ? ( + {statement.text} + ) : s.nextRenewalDate ? ( +
+
+ {formatDay(s.nextRenewalDate)} + {s.daysUntilRenewal !== null && } +
+ {s.cancellationDeadline && s.cancellationDeadline >= today && ( + Cancel by {formatDay(s.cancellationDeadline)} to avoid paying + )} + {!s.autoRenew && Pay it manually — doesn't auto-renew} +
+ ) : ( + — + ); return ( - - - e.stopPropagation()}> - {s.name} - -
- {s.planName && {s.planName}} - {s.categoryName && } - - +
  • +
    +
    + + {s.name.trim().charAt(0) || "?"} +
    + + {s.name} + +
    + {s.categoryName ? : {s.provider}} +
    +
    -

    - {statement.text} -

    - - -
    - - + +
    +
    {money(s.amount, s.currency)}
    +
    + {s.billingLabel} + {s.currency !== s.baseCurrency && s.baseAmount !== null && ≈ {money(s.baseAmount)}} +
    - - -
    {money(s.amount, s.currency)}
    -
    {s.billingLabel}
    - {s.currency !== s.baseCurrency && s.baseAmount !== null && ( -
    ≈ {money(s.baseAmount)}
    - )} - - - -

    - {statement.text} -

    - - - {s.cancellationDeadline ? ( - - ) : ( - — - )} - - - {onPay && ( - - )} - - + +
    + +
    + +
    + {next} + {onPay && ( + + )} +
    +
    +
  • ); } -function Breakdown({ - title, - rows, -}: { - title: string; - rows: Array<{ key: string; label: string; count: number; monthly: number; annual: number; href?: string }>; -}) { +type BreakdownRow = { key: string; label: string; count: number; monthly: number; annual: number }; + +/** Where the monthly cost goes, one grouping at a time. */ +function Breakdown({ groups }: { groups: Array<{ key: string; label: string; rows: BreakdownRow[] }> }) { const { money } = useApp(); - const max = Math.max(1, ...rows.map((r) => r.monthly)); + const [active, setActive] = useState(groups[0]?.key); + const group = groups.find((g) => g.key === active) ?? groups[0]; + if (!group) return null; + const max = Math.max(1, ...group.rows.map((r) => r.monthly)); return ( -
    - {rows.length === 0 ? ( +
    + {groups.length > 1 && ( +
    + {groups.map((g) => ( + + ))} +
    + )} + {group.rows.length === 0 ? ( No active subscriptions. ) : ( -
      - {rows.map((row) => { - const body = ( - <> -
      - - {row.label} · {row.count} - - {money(row.monthly)} -
      - -
      {money(row.annual)} a year
      - - ); - return ( -
    • - {row.href ? ( - - {body} - - ) : ( - body - )} -
    • - ); - })} +
        + {group.rows.map((row) => ( +
      • +
        + + {row.label} · {row.count} + + + {money(row.monthly)} + /mo + +
        + +
        {money(row.annual)} a year
        +
      • + ))}
      )}
    diff --git a/apps/web/src/components/settings/account-settings.tsx b/apps/web/src/components/settings/account-settings.tsx index 3fa314d..2401655 100644 --- a/apps/web/src/components/settings/account-settings.tsx +++ b/apps/web/src/components/settings/account-settings.tsx @@ -1,5 +1,6 @@ "use client"; +import { DEFAULT_REMINDER_OFFSETS } from "@expensewise/core"; import { Copy, Download, KeyRound, Laptop, LogOut, MailCheck, ShieldCheck, ShieldOff, Smartphone } from "lucide-react"; import { useRouter } from "next/navigation"; import { useEffect, useId, useMemo, useState } from "react"; @@ -308,7 +309,7 @@ export function NotificationSettings() { const { me, workspace, canManage } = useApp(); const router = useRouter(); const [email, setEmail] = useState(me.preferences.notifications?.email ?? true); - const [offsets, setOffsets] = useState((workspace.settings.reminderOffsets ?? [30, 14, 7, 3, 1, 0]).join(", ")); + const [offsets, setOffsets] = useState((workspace.settings.reminderOffsets ?? DEFAULT_REMINDER_OFFSETS).join(", ")); const [saving, setSaving] = useState(false); const save = async () => { diff --git a/apps/web/src/components/transactions/transaction-detail.tsx b/apps/web/src/components/transactions/transaction-detail.tsx index 5a6e955..cb2566b 100644 --- a/apps/web/src/components/transactions/transaction-detail.tsx +++ b/apps/web/src/components/transactions/transaction-detail.tsx @@ -1,6 +1,6 @@ "use client"; -import { TYPE_LABELS } from "@expensewise/core"; +import { monthKey, TYPE_LABELS } from "@expensewise/core"; import { AlertTriangle, Check, FileText, Loader2, Paperclip, Pencil, Trash2, X } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; @@ -25,6 +25,7 @@ import { ATTACHMENT_ACCEPT, attachmentProblem, deleteFile, fileUrl, uploadFile } import type { TransactionDetail } from "@/lib/api/types"; import { cn } from "@/lib/cn"; import { formatBytes, formatDateTime, formatDay, titleFromKind } from "@/lib/format"; +import { formatMonth } from "@/lib/format-client"; import { toast } from "@/lib/toast"; const ACTION_LABELS: Record = { @@ -122,7 +123,13 @@ export function TransactionDetailDrawer({ id, onClose }: { id: string | null; on
    {TYPE_LABELS[detail.type]} · - {formatDay(detail.date, "long")} + {detail.type === "income" ? ( + + Profit month {formatMonth(monthKey(detail.date))} · recorded {formatDateTime(detail.createdAt)} + + ) : ( + {formatDay(detail.date, "long")} + )}
    diff --git a/apps/web/src/components/transactions/transactions-view.tsx b/apps/web/src/components/transactions/transactions-view.tsx index 2d5277f..36af775 100644 --- a/apps/web/src/components/transactions/transactions-view.tsx +++ b/apps/web/src/components/transactions/transactions-view.tsx @@ -1,6 +1,6 @@ "use client"; -import { TYPE_LABELS } from "@expensewise/core"; +import { monthKey, TYPE_LABELS } from "@expensewise/core"; import { ArrowLeftRight, ChevronLeft, ChevronRight, Paperclip, Plus, Search, Sparkles, X } from "lucide-react"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useEffect, useState, useTransition } from "react"; @@ -14,6 +14,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@ import type { Account, Category, Project, TransactionListItem, TransactionPage } from "@/lib/api/types"; import { cn } from "@/lib/cn"; import { formatDay } from "@/lib/format"; +import { formatMonth } from "@/lib/format-client"; import { PERIODS, type TransactionFilters, TYPE_TABS } from "./filters"; const ALL = "__all__"; @@ -305,13 +306,15 @@ function Row({ tx, isBusiness, onOpen }: { tx: TransactionListItem; isBusiness: : (tx.counterpartyName ?? tx.merchant ?? tx.description ?? TYPE_LABELS[tx.type]); const secondary = tx.type === "transfer" ? tx.description : tx.counterpartyName || tx.merchant ? tx.description : null; const foreign = tx.baseCurrency && tx.currency !== tx.baseCurrency; + // Income is entered per profit month, so it shows the month and year, not a day. + const when = tx.type === "income" ? formatMonth(monthKey(tx.date), "en-GB", true) : formatDay(tx.date); return ( - {formatDay(tx.date)} + {when}

    - {formatDay(tx.date)} · {tx.accountName} + {when} · {tx.accountName}

    {title} diff --git a/apps/web/src/components/wealth/assets.tsx b/apps/web/src/components/wealth/assets.tsx index fc3ca61..0aa67f5 100644 --- a/apps/web/src/components/wealth/assets.tsx +++ b/apps/web/src/components/wealth/assets.tsx @@ -298,6 +298,7 @@ export function AssetFormDialog({ open, onOpenChange, asset }: { open: boolean; const value = currentValue ? toMinor(currentValue, currency) : price; if (value === null) return setError("Enter what it is worth now (or its purchase price)"); if (recordPayment && !accountId) return setError("Choose the account it was paid from"); + if (recordPayment && !invoice.length) return setError("Attach the purchase invoice. If a file is still uploading, wait for it to finish."); if (recordPayment && !price) return setError("Enter the purchase price to record the payment"); const common = { name: name.trim(), @@ -409,8 +410,8 @@ export function AssetFormDialog({ open, onOpenChange, asset }: { open: boolean; )} diff --git a/apps/web/src/components/wealth/investments.tsx b/apps/web/src/components/wealth/investments.tsx index 617ee72..89d7a46 100644 --- a/apps/web/src/components/wealth/investments.tsx +++ b/apps/web/src/components/wealth/investments.tsx @@ -506,6 +506,7 @@ export function FlowDialog({ if (!minor) return setError("Enter the amount"); if (!accountId) return setError(direction === "out" ? "Choose the account the money came from" : "Choose the account the money went into"); if (costBasis && basis === null) return setError("Enter the cost basis as a number"); + if (!attachments.length) return setError("Attach the statement or receipt. If a file is still uploading, wait for it to finish."); setSaving(true); setError(null); try { @@ -581,7 +582,7 @@ export function FlowDialog({ setNote(e.target.value)} /> - + diff --git a/apps/web/src/components/wealth/liabilities.tsx b/apps/web/src/components/wealth/liabilities.tsx index 2821ce0..52c58b0 100644 --- a/apps/web/src/components/wealth/liabilities.tsx +++ b/apps/web/src/components/wealth/liabilities.tsx @@ -680,6 +680,7 @@ export function PaymentDialog({ open, onOpenChange, liability }: { open: boolean if (!total) return setError("Enter the amount paid"); if (interestMinor === null || interestMinor > total) return setError("Interest has to be part of the payment"); if (!accountId) return setError("Choose the account you paid from"); + if (!attachments.length) return setError("Attach the receipt. If a file is still uploading, wait for it to finish."); setSaving(true); setError(null); try { @@ -778,7 +779,7 @@ export function PaymentDialog({ open, onOpenChange, liability }: { open: boolean setNote(e.target.value)} /> - + diff --git a/apps/web/src/components/wealth/receivables.tsx b/apps/web/src/components/wealth/receivables.tsx index d809c86..040f0de 100644 --- a/apps/web/src/components/wealth/receivables.tsx +++ b/apps/web/src/components/wealth/receivables.tsx @@ -517,6 +517,7 @@ export function ReceivablePaymentDialog({ open, onOpenChange, receivable }: { op const minor = toMinor(amount, receivable.currency); if (!minor) return setError("Enter the amount received"); if (!accountId) return setError("Choose the account it arrived in"); + if (!attachments.length) return setError("Attach the proof of payment. If a file is still uploading, wait for it to finish."); setSaving(true); setError(null); try { @@ -574,8 +575,8 @@ export function ReceivablePaymentDialog({ open, onOpenChange, receivable }: { op diff --git a/apps/web/src/lib/api/types/business.ts b/apps/web/src/lib/api/types/business.ts index 65fb52c..7d5cb33 100644 --- a/apps/web/src/lib/api/types/business.ts +++ b/apps/web/src/lib/api/types/business.ts @@ -85,6 +85,19 @@ export type ProjectProfile = { share: number | null; drill: Drill; }>; + revenueByCategory: Array<{ + categoryId: string | null; + name: string; + amount: number; + share: number | null; + drill: Drill; + }>; + revenueByMonth: Array<{ + month: string; + amount: number; + drill: Drill; + categories: Array<{ categoryId: string | null; name: string; amount: number; drill: Drill }>; + }>; topVendors: Array<{ counterpartyId: string | null; name: string; diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 4ef3037..0558615 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -151,7 +151,7 @@ export type InboxKind = (typeof INBOX_KINDS)[number]; export const SEVERITIES = ["info", "success", "warning", "critical"] as const; export type Severity = (typeof SEVERITIES)[number]; -export const DEFAULT_REMINDER_OFFSETS = [30, 14, 7, 3, 1, 0]; +export const DEFAULT_REMINDER_OFFSETS = [2, 1, 0]; /** Where a type sits in reports. Only these move profit and loss. */ export const TYPE_LABELS: Record = { diff --git a/packages/core/src/contracts/business-extra.ts b/packages/core/src/contracts/business-extra.ts index 94f5b6a..b1cbd62 100644 --- a/packages/core/src/contracts/business-extra.ts +++ b/packages/core/src/contracts/business-extra.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import { dayString } from "./common.ts"; +import { dayString, uuid } from "./common.ts"; import { employeeInput } from "./operations.ts"; // Request shapes for the business API that the base contracts do not cover. @@ -38,4 +38,6 @@ export type EmployeeCreateInput = z.input; export const employeeQuery = z.object({ status: z.enum(["active", "inactive", "all"]).default("all"), + /** Only the people whose cost belongs to this project. */ + projectId: uuid.optional(), }); diff --git a/packages/core/tests/finance.test.ts b/packages/core/tests/finance.test.ts index 146c142..c43aeb5 100644 --- a/packages/core/tests/finance.test.ts +++ b/packages/core/tests/finance.test.ts @@ -150,29 +150,31 @@ describe("schedules", () => { describe("subscription alerts", () => { it("fires each reminder offset once, catching up after a gap", () => { - expect(dueReminderOffset(30)).toBe(30); - expect(dueReminderOffset(29)).toBe(30); - expect(dueReminderOffset(7)).toBe(7); - expect(dueReminderOffset(5)).toBe(7); + // Default: two days before, the day before, and on the day. + expect(dueReminderOffset(3)).toBeNull(); + expect(dueReminderOffset(2)).toBe(2); + expect(dueReminderOffset(1)).toBe(1); expect(dueReminderOffset(0)).toBe(0); - expect(dueReminderOffset(45)).toBeNull(); + expect(dueReminderOffset(30)).toBeNull(); + expect(dueReminderOffset(29, [30, 7])).toBe(30); + expect(dueReminderOffset(5, [30, 7])).toBe(7); expect(dueReminderOffset(45, [45, 7])).toBe(45); }); it("says manual renewal is needed when auto-renew is off", () => { - const alerts = renewalAlerts({ name: "Figma", amountLabel: "$180", autoRenew: false, dueDate: "2027-10-10", expiryDate: "2027-10-10" }, "2027-10-03"); + const alerts = renewalAlerts({ name: "Figma", amountLabel: "$180", autoRenew: false, dueDate: "2027-10-10", expiryDate: "2027-10-10" }, "2027-10-08"); expect(alerts).toHaveLength(1); - expect(alerts[0]).toMatchObject({ kind: "renewal", offset: 7, stage: "soon" }); + expect(alerts[0]).toMatchObject({ kind: "renewal", offset: 2, stage: "soon" }); expect(alerts[0]?.body).toContain("Manual renewal required"); }); it("warns about a cancellation deadline separately from the renewal", () => { const alerts = renewalAlerts( - { name: "Figma", amountLabel: "$180", autoRenew: true, dueDate: "2027-10-10", cancellationDeadline: "2027-10-03" }, - "2027-09-28", + { name: "Figma", amountLabel: "$180", autoRenew: true, dueDate: "2027-10-04", cancellationDeadline: "2027-10-03" }, + "2027-10-02", ); expect(alerts.map((a) => a.kind).sort()).toEqual(["cancellation_deadline", "renewal"]); - expect(alerts.find((a) => a.kind === "cancellation_deadline")?.title).toContain("in 5 days"); + expect(alerts.find((a) => a.kind === "cancellation_deadline")?.title).toContain("tomorrow"); }); it("flags a renewal that passed without a recorded payment", () => {