Design database schemas for PostgreSQL, Neon, Convex, or Supabase. Use when users need to create tables, define relationships, plan migrations, optimize indexes, or implement data models. Covers normalization, denormalization strategies, and platform-specific features.
/plugin marketplace add leobrival/topographic-studio-plugins/plugin install code-workflows@topographic-studio-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/convex/mutations.tsassets/convex/queries.tsassets/convex/schema.tsassets/neon/branching.tsassets/neon/db-client.tsassets/neon/drizzle-config.tsassets/neon/migrations-workflow.tsassets/postgresql/drizzle-schema.tsassets/postgresql/indexes-template.sqlassets/postgresql/migration-template.sqlassets/postgresql/prisma-schema.prismaassets/supabase/functions.sqlassets/supabase/rls-policies.sqlassets/supabase/schema.sqlreferences/convex-patterns.mdreferences/indexes.mdreferences/migrations.mdreferences/neon-patterns.mdreferences/normalization.mdreferences/postgresql-patterns.mdDesign robust, scalable database schemas for modern applications.
User request → Which platform?
│
├─ PostgreSQL (Traditional SQL)
│ ├─ Hosting?
│ │ ├─ Neon → Serverless, branching, scale-to-zero
│ │ ├─ Supabase → BaaS, realtime, auth
│ │ ├─ Railway → Simple deployment
│ │ ├─ Vercel Postgres → Edge-optimized
│ │ └─ Self-hosted → Full control
│ │
│ ├─ ORM?
│ │ ├─ Drizzle → Type-safe, lightweight
│ │ ├─ Prisma → Full-featured, migrations
│ │ ├─ Kysely → Type-safe query builder
│ │ └─ Raw SQL → Maximum control
│ │
│ └─ What to design?
│ ├─ Schema → Tables, columns, types
│ ├─ Relations → FK, joins, constraints
│ ├─ Indexes → Performance optimization
│ └─ Migrations → Version control
│
├─ Neon (Serverless PostgreSQL)
│ ├─ Branching → Dev/preview environments
│ ├─ Scale-to-zero → Cost optimization
│ ├─ Pooling → Connection management
│ └─ Extensions → Full PostgreSQL support
│
├─ Convex (Serverless NoSQL)
│ ├─ Schema → TypeScript validators
│ ├─ Indexes → Query optimization
│ ├─ Relations → Document references
│ └─ Functions → Queries, mutations
│
└─ Supabase (PostgreSQL + BaaS)
├─ Tables → SQL + Dashboard
├─ RLS → Row Level Security policies
├─ Triggers → Automatic actions
├─ Functions → PL/pgSQL
└─ Realtime → Live subscriptions
// schema.ts
import { pgTable, text, timestamp, uuid, integer } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: uuid("id").primaryKey().defaultRandom(),
email: text("email").notNull().unique(),
name: text("name").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
export const posts = pgTable("posts", {
id: uuid("id").primaryKey().defaultRandom(),
title: text("title").notNull(),
content: text("content"),
authorId: uuid("author_id").references(() => users.id).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// convex/schema.ts
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
export default defineSchema({
users: defineTable({
email: v.string(),
name: v.string(),
createdAt: v.number(),
})
.index("by_email", ["email"]),
posts: defineTable({
title: v.string(),
content: v.optional(v.string()),
authorId: v.id("users"),
createdAt: v.number(),
})
.index("by_author", ["authorId"]),
});
-- Create tables
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE posts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title TEXT NOT NULL,
content TEXT,
author_id UUID REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Enable RLS
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
ALTER TABLE posts ENABLE ROW LEVEL SECURITY;
-- RLS Policies
CREATE POLICY "Users can read own data"
ON users FOR SELECT
USING (auth.uid() = id);
// drizzle.config.ts for Neon
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./src/db/schema.ts",
out: "./drizzle",
dialect: "postgresql",
dbCredentials: {
url: process.env.DATABASE_URL!, // Neon connection string
},
});
// db.ts - Neon serverless driver
import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from "./schema";
const sql = neon(process.env.DATABASE_URL!);
export const db = drizzle(sql, { schema });
// For connection pooling (recommended for serverless)
import { Pool } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-serverless";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export const db = drizzle(pool, { schema });
| Need | Platform | Why |
|---|---|---|
| Type-safe serverless | Convex | Built-in TypeScript, reactive |
| Serverless PostgreSQL | Neon | Scale-to-zero, branching, fast cold starts |
| Full PostgreSQL features | Neon/Supabase | Standard SQL, extensions |
| Auth + Storage + DB | Supabase | All-in-one BaaS |
| Complex queries | PostgreSQL | JOINs, CTEs, window functions |
| Real-time sync | Convex or Supabase | Built-in subscriptions |
| Document-style data | Convex | Flexible schema |
| Relational data | PostgreSQL/Supabase/Neon | Strong consistency |
| Rapid prototyping | Convex | Zero config, instant |
| Preview environments | Neon | Database branching |
| Cost optimization | Neon | Scale-to-zero billing |
// Drizzle
export const users = pgTable("users", {
id: uuid("id").primaryKey().defaultRandom(),
email: text("email").notNull().unique(),
});
export const profiles = pgTable("profiles", {
userId: uuid("user_id").primaryKey().references(() => users.id),
bio: text("bio"),
avatarUrl: text("avatar_url"),
});
export const posts = pgTable("posts", {
id: uuid("id").primaryKey().defaultRandom(),
title: text("title").notNull(),
});
export const tags = pgTable("tags", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull().unique(),
});
export const postTags = pgTable("post_tags", {
postId: uuid("post_id").references(() => posts.id).notNull(),
tagId: uuid("tag_id").references(() => tags.id).notNull(),
}, (t) => ({
pk: primaryKey(t.postId, t.tagId),
}));
export const posts = pgTable("posts", {
id: uuid("id").primaryKey().defaultRandom(),
title: text("title").notNull(),
deletedAt: timestamp("deleted_at"),
});
// Query active posts
const activePosts = await db
.select()
.from(posts)
.where(isNull(posts.deletedAt));
export const auditLogs = pgTable("audit_logs", {
id: uuid("id").primaryKey().defaultRandom(),
tableName: text("table_name").notNull(),
recordId: uuid("record_id").notNull(),
action: text("action").notNull(), // INSERT, UPDATE, DELETE
oldData: jsonb("old_data"),
newData: jsonb("new_data"),
userId: uuid("user_id").references(() => users.id),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
created_at, updated_at on every tabledeleted_at instead of hard deletesThis skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.