29 lines
902 B
SQL
29 lines
902 B
SQL
CREATE TABLE recurring_transactions (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
|
|
name TEXT NOT NULL,
|
|
account_id UUID NOT NULL CONSTRAINT fk_recurring_transactions_account REFERENCES accounts (id),
|
|
amount_cents BIGINT NOT NULL CHECK (amount_cents >= 0),
|
|
direction TEXT NOT NULL CHECK (direction IN ('in', 'out')),
|
|
starts_at TIMESTAMPTZ NOT NULL,
|
|
ends_at TIMESTAMPTZ,
|
|
recurrence_every INTEGER NOT NULL CHECK (recurrence_every > 0),
|
|
recurrence_unit TEXT NOT NULL CHECK (
|
|
recurrence_unit IN (
|
|
'day',
|
|
'week',
|
|
'month',
|
|
'year'
|
|
)
|
|
),
|
|
weekend_adjustment TEXT CHECK (
|
|
weekend_adjustment IS NULL
|
|
OR weekend_adjustment IN (
|
|
'previous_business_day',
|
|
'next_business_day'
|
|
)
|
|
),
|
|
CHECK (
|
|
ends_at IS NULL
|
|
OR ends_at >= starts_at
|
|
)
|
|
); |