Visual Supabase Schema & RLS Builder

Model relational schemas visually and copy clean PostgreSQL DDL pre-configured with foreign key indexes and starter Row Level Security policies.

Templates:
organizations5 cols
id
uuid
name
varchar
slug
varchar
plan
varchar
created_at
timestamp
users5 cols
id
uuid
organization_id
uuid
email
varchar
role
varchar
is_active
boolean
subscriptions6 cols
id
uuid
organization_id
uuid
provider_id
varchar
status
varchar
price_cents
int
renews_at?
timestamp
audit_logs5 cols
id
serial
user_id?
uuid
action
varchar
metadata?
jsonb
created_at
timestamp
Drag tables to arrange your ERD · Click any table to edit columns & relations
-- Generated by SchemaCost (Supabase + RLS)
CREATE EXTENSION IF NOT EXISTS "pgcrypto";

CREATE TABLE "organizations" (
  "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  "name" VARCHAR(255) NOT NULL,
  "slug" VARCHAR(255) NOT NULL UNIQUE,
  "plan" VARCHAR(255) NOT NULL DEFAULT 'free',
  "created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE TABLE "users" (
  "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  "organization_id" UUID NOT NULL REFERENCES "organizations"("id") ON DELETE CASCADE,
  "email" VARCHAR(255) NOT NULL UNIQUE,
  "role" VARCHAR(255) NOT NULL DEFAULT 'member',
  "is_active" BOOLEAN NOT NULL DEFAULT true
);

CREATE TABLE "subscriptions" (
  "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  "organization_id" UUID NOT NULL UNIQUE REFERENCES "organizations"("id") ON DELETE CASCADE,
  "provider_id" VARCHAR(255) NOT NULL UNIQUE,
  "status" VARCHAR(255) NOT NULL,
  "price_cents" INTEGER NOT NULL,
  "renews_at" TIMESTAMPTZ
);

CREATE TABLE "audit_logs" (
  "id" BIGSERIAL PRIMARY KEY,
  "user_id" UUID REFERENCES "users"("id") ON DELETE SET NULL,
  "action" VARCHAR(255) NOT NULL,
  "metadata" JSONB,
  "created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Foreign Key Indexes
CREATE INDEX "idx_users_organization_id" ON "users" ("organization_id");
CREATE INDEX "idx_subscriptions_organization_id" ON "subscriptions" ("organization_id");
CREATE INDEX "idx_audit_logs_user_id" ON "audit_logs" ("user_id");

-- Supabase Row Level Security (Starter Policies)
ALTER TABLE "organizations" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "authenticated_read_organizations" ON "organizations" FOR SELECT TO authenticated USING (true);
ALTER TABLE "users" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "authenticated_read_users" ON "users" FOR SELECT TO authenticated USING (true);
ALTER TABLE "subscriptions" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "authenticated_read_subscriptions" ON "subscriptions" FOR SELECT TO authenticated USING (true);
ALTER TABLE "audit_logs" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "authenticated_read_audit_logs" ON "audit_logs" FOR SELECT TO authenticated USING (true);

Key Highlights

  • ✓ Automatically creates foreign key indexes to prevent slow joins and deletes.
  • ✓ Includes SaaS Multi-Tenant, E-Commerce, Fintech, and Social starter templates.

Frequently Asked Questions

Does Supabase require RLS on public tables?

Yes, enabling Row Level Security is strongly recommended on every exposed table in Supabase so client keys cannot read unauthorized rows.