Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table public.users (
- created_at timestamp with time zone not null default now(),
- settings jsonb null default '{}'::jsonb,
- id uuid not null default auth.uid(),
- theme jsonb null,
- constraint users_pkey primary key (id),
- constraint users_id_key unique (id)
- ) TABLESPACE pg_default;
- create table public.customers (
- id uuid not null default gen_random_uuid (),
- created_at timestamp with time zone not null default now(),
- name text null default 'User'::text,
- user_id uuid null,
- discord_id text null,
- constraint customers_pkey primary key (id),
- constraint customers_discord_id_key unique (discord_id),
- constraint customers_user_id_fkey foreign KEY (user_id) references users (id) on update CASCADE on delete CASCADE
- ) TABLESPACE pg_default;
- create table public.products (
- id uuid not null default gen_random_uuid (),
- created_at timestamp with time zone not null default now(),
- name text null default 'New Product'::text,
- image_url text null,
- version text null default 'v1'::text,
- price double precision null default '0'::double precision,
- enabled boolean null default true,
- user_id uuid null default auth.uid(),
- constraint products_pkey primary key (id),
- constraint products_user_id_fkey foreign KEY (user_id) references users (id) on update CASCADE on delete CASCADE
- ) TABLESPACE pg_default;
- create table public.licenses (
- id bigint generated by default as identity not null,
- customer uuid null,
- product uuid null,
- issue_date timestamp with time zone null default now(),
- expiration timestamp with time zone null,
- license_key text null,
- user_id uuid null,
- updated_at timestamp with time zone null,
- status text null default 'active'::text,
- used_ips text[] null default '{}'::text[],
- max_ips smallint null default '1'::smallint,
- constraint licenses_pkey primary key (id),
- constraint licenses_id_key unique (id),
- constraint licenses_license_key_key unique (license_key),
- constraint licenses_customer_fkey foreign KEY (customer) references customers (id) on update CASCADE on delete CASCADE,
- constraint licenses_product_fkey foreign KEY (product) references products (id) on update CASCADE on delete CASCADE,
- constraint licenses_user_id_fkey foreign KEY (user_id) references users (id) on update CASCADE on delete CASCADE,
- constraint licenses_check check (true)
- ) TABLESPACE pg_default;
- create table public.logs (
- id bigint generated by default as identity not null,
- created_at timestamp with time zone not null default now(),
- license_key text null,
- ip_address text null,
- metadata jsonb null default '{}'::jsonb,
- status text null default 'Unknown'::text,
- user_id uuid null default auth.uid(),
- constraint logs_pkey primary key (id),
- constraint logs_id_key unique (id),
- constraint logs_license_key_fkey foreign KEY (license_key) references licenses (license_key) on update CASCADE on delete CASCADE,
- constraint logs_user_id_fkey foreign KEY (user_id) references users (id) on update CASCADE on delete CASCADE
- ) TABLESPACE pg_default;
- alter publication supabase_realtime add table public.logs;
- alter table public.users enable row level security;
- alter table public.licenses enable row level security;
- alter table public.logs enable row level security;
- alter table public.products enable row level security;
- alter table public.customers enable row level security;
- create policy "Users can access their own record"
- on public.users
- for all
- using (auth.uid() = id);
- create policy "Users can select their own licenses"
- on public.licenses
- for select
- using (auth.uid() = customer);
- create policy "Users can select their own products"
- on public.products
- for all
- using (auth.uid() = user_id);
- create policy "Users can view their own logs"
- on public.logs
- for select
- using (auth.uid() = user_id);
- create policy "Users can access their own customer record"
- on public.customers
- for all
- using (auth.uid() = user_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement