26 lines
788 B
SQL
26 lines
788 B
SQL
-- Category type enum
|
|
create type category_type as enum (
|
|
'income', 'bill', 'variable_expense', 'debt', 'saving', 'investment'
|
|
);
|
|
|
|
-- Categories table
|
|
create table categories (
|
|
id uuid primary key default gen_random_uuid(),
|
|
user_id uuid not null references auth.users(id) on delete cascade,
|
|
name text not null,
|
|
type category_type not null,
|
|
icon text,
|
|
sort_order int not null default 0,
|
|
created_at timestamptz not null default now(),
|
|
updated_at timestamptz not null default now()
|
|
);
|
|
|
|
create index categories_user_id_idx on categories(user_id);
|
|
|
|
alter table categories enable row level security;
|
|
|
|
create policy "Users can CRUD own categories"
|
|
on categories for all
|
|
using (user_id = auth.uid())
|
|
with check (user_id = auth.uid());
|