25 lines
1.2 KiB
SQL
25 lines
1.2 KiB
SQL
CREATE TABLE IF NOT EXISTS policy_payments (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
policy_id INTEGER NOT NULL REFERENCES policies(id) ON DELETE CASCADE,
|
|
due_date TEXT NOT NULL,
|
|
amount INTEGER NOT NULL DEFAULT 0 CHECK (amount >= 0),
|
|
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending','paid','skipped')),
|
|
paid_date TEXT NOT NULL DEFAULT '',
|
|
note TEXT NOT NULL DEFAULT '',
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_policy_payments_policy_due ON policy_payments(policy_id, due_date);
|
|
|
|
CREATE TABLE IF NOT EXISTS account_reconciliations (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
|
|
system_balance INTEGER NOT NULL,
|
|
actual_balance INTEGER NOT NULL,
|
|
difference INTEGER NOT NULL,
|
|
transaction_id INTEGER REFERENCES transactions(id) ON DELETE SET NULL,
|
|
note TEXT NOT NULL DEFAULT '',
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_account_reconciliations_account ON account_reconciliations(account_id, created_at);
|