Templates:
organizations5 cols
id
uuidname
varcharslug
varcharplan
varcharcreated_at
timestampusers5 cols
id
uuidorganization_id
uuidemail
varcharrole
varcharis_active
booleansubscriptions6 cols
id
uuidorganization_id
uuidprovider_id
varcharstatus
varcharprice_cents
intrenews_at?
timestampaudit_logs5 cols
id
serialuser_id?
uuidaction
varcharmetadata?
jsonbcreated_at
timestampDrag 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);