| -- ONLY for a throwaway local database, not a production migration. | |
| create schema if not exists auth; | |
| do $$ begin if not exists(select 1 from pg_roles where rolname='anon') then create role anon; end if; if not exists(select 1 from pg_roles where rolname='authenticated') then create role authenticated; end if; end $$; | |
| create function auth.uid() returns uuid language sql stable as $$select nullif(current_setting('request.jwt.claim.sub',true),'')::uuid$$; | |
| create table auth.users(id uuid primary key,email text not null,banned_until timestamptz); | |
| create table public.organizations(id uuid primary key,slug text unique not null,name text not null,plan text not null default 'free',subscription_status text,settings jsonb not null default '{}',deleted_at timestamptz); | |
| create table public.org_members(org_id uuid references public.organizations(id),user_id uuid references auth.users(id),role text not null,monthly_credit_limit numeric,suspended_at timestamptz,primary key(org_id,user_id)); | |
| create table public.lightning_api_keys(id uuid primary key,user_id uuid references auth.users(id),org_id uuid references public.organizations(id),key_prefix text not null unique,key_hash text not null,revoked_at timestamptz,expires_at timestamptz,ip_allowlist jsonb,rate_limit_rpm integer,monthly_credit_limit numeric); | |
| create table public.user_wallets(user_id uuid primary key references auth.users(id),monthly_spend_limit numeric,balance_credits numeric not null,paid_credits numeric not null default 100,promotional_credits numeric not null default 0,updated_at timestamptz not null default now()); | |
| create table public.org_wallets(org_id uuid primary key references public.organizations(id),monthly_spend_limit numeric,balance_credits numeric not null,paid_credits numeric not null default 100,promotional_credits numeric not null default 0,updated_at timestamptz not null default now()); | |
| create table public.credit_ledger(id uuid primary key default gen_random_uuid(),user_id uuid references auth.users(id),delta_credits numeric not null,balance_after numeric not null,entry_type text not null,usage_kind text,units numeric,unit_label text,source text,source_ref text,idempotency_key text unique,metadata jsonb,model text,created_at timestamptz not null default now()); | |
| create table public.org_credit_ledger(actor_user_id uuid,api_key_id uuid,key_prefix text,id uuid primary key default gen_random_uuid(),org_id uuid references public.organizations(id),delta_credits numeric not null,balance_after numeric not null,entry_type text not null,usage_kind text,units numeric,unit_label text,source text,source_ref text,idempotency_key text unique,metadata jsonb,model text,created_at timestamptz not null default now()); | |
| create table if not exists public.org_audit_log(id bigint generated always as identity primary key,org_id uuid not null,actor_id uuid,actor_type text not null,action text not null,target_type text,target_id text,metadata jsonb not null default '{}',created_at timestamptz not null default now()); | |
| do $$ begin | |
| if not exists(select 1 from pg_roles where rolname='service_role') then | |
| create role service_role nologin bypassrls; | |
| end if; | |
| end $$; | |
Xet Storage Details
- Size:
- 3.16 kB
- Xet hash:
- f3015032b7bccf2bcc03cbb45453df48e9557eff8d85e4b59aa6a4eb100ccc80
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.