Files
myeasycms-v2/.claude/skills/postgres-expert/examples.md
Giancarlo Buomprisco cfa137795b refactor: consolidate AGENTS.md and CLAUDE.md files, update tech stac… (#444)
* refactor: consolidate AGENTS.md and CLAUDE.md files, update tech stack and architecture details

- Merged content from CLAUDE.md into AGENTS.md for better organization.
- Updated tech stack section to reflect the current technologies used, including Next.js, Supabase, and Tailwind CSS.
- Enhanced monorepo structure documentation with detailed directory purposes.
- Streamlined multi-tenant architecture explanation and essential commands.
- Added key patterns for naming conventions and server actions.
- Removed outdated agent files related to Playwright and PostgreSQL, ensuring a cleaner codebase.
- Bumped version to 2.23.7 to reflect changes.
2026-01-18 10:44:40 +01:00

3.8 KiB

Makerkit Database Examples

Real examples from the codebase.

Accounts Schema

Location: apps/web/supabase/schemas/03-accounts.sql

create table if not exists public.accounts (
  id uuid unique not null default extensions.uuid_generate_v4(),
  primary_owner_user_id uuid references auth.users on delete cascade not null,
  name varchar(255) not null,
  slug varchar(255) unique,
  is_personal_account boolean not null default false,
  picture_url varchar(1000),
  created_at timestamp with time zone default now(),
  updated_at timestamp with time zone default now(),
  primary key (id)
);

alter table "public"."accounts" enable row level security;

Account Memberships

Location: apps/web/supabase/schemas/04-accounts-memberships.sql

create table if not exists public.accounts_memberships (
  account_id uuid references public.accounts(id) on delete cascade not null,
  user_id uuid references auth.users(id) on delete cascade not null,
  account_role varchar(50) not null,
  created_at timestamp with time zone default now(),
  updated_at timestamp with time zone default now(),
  created_by uuid references auth.users(id),
  updated_by uuid references auth.users(id),
  primary key (account_id, user_id)
);

-- RLS policies using helper functions
create policy accounts_memberships_select on public.accounts_memberships
  for select to authenticated using (
    user_id = (select auth.uid())
    or public.has_role_on_account(account_id)
  );

Subscriptions

Location: apps/web/supabase/schemas/11-subscriptions.sql

create table if not exists public.subscriptions (
  id varchar(255) not null,
  account_id uuid not null references public.accounts(id) on delete cascade,
  billing_customer_id varchar(255) not null,
  status public.subscription_status not null,
  currency varchar(10) not null,
  cancel_at_period_end boolean not null default false,
  period_starts_at timestamp with time zone,
  period_ends_at timestamp with time zone,
  trial_starts_at timestamp with time zone,
  trial_ends_at timestamp with time zone,
  created_at timestamp with time zone not null default now(),
  updated_at timestamp with time zone not null default now(),
  primary key (id)
);

Notifications

Location: apps/web/supabase/schemas/12-notifications.sql

create table if not exists public.notifications (
  id uuid primary key default extensions.uuid_generate_v4(),
  account_id uuid references public.accounts(id) on delete cascade not null,
  type public.notification_type not null,
  body jsonb not null default '{}',
  dismissed boolean not null default false,
  link text,
  created_at timestamptz default now() not null
);

-- Only account members can see notifications
create policy read_notifications on public.notifications
  for select to authenticated using (
    public.has_role_on_account(account_id)
  );

Storage Bucket

Location: apps/web/supabase/schemas/16-storage.sql

insert into storage.buckets (id, name, public)
values ('account_image', 'account_image', true)
on conflict (id) do nothing;

create policy account_image on storage.objects for all using (
  bucket_id = 'account_image'
  and (
    kit.get_storage_filename_as_uuid(name) = auth.uid()
    or public.has_role_on_account(kit.get_storage_filename_as_uuid(name))
  )
)
with check (
  bucket_id = 'account_image'
  and (
    kit.get_storage_filename_as_uuid(name) = auth.uid()
    or public.has_permission(
      auth.uid(),
      kit.get_storage_filename_as_uuid(name),
      'settings.manage'
    )
  )
);

Enum Types

-- Subscription status
create type public.subscription_status as enum (
  'active',
  'trialing',
  'past_due',
  'canceled',
  'unpaid',
  'incomplete',
  'incomplete_expired',
  'paused'
);

-- App permissions
create type public.app_permissions as enum (
  'settings.manage',
  'billing.manage',
  'members.manage',
  'invitations.manage'
);