database-schema-design
Skill11 starsChanged 9 months agoApache-2.0View on GitHub
Database schema design patterns for SQL and NoSQL databases
3 other projects use a version of this.
Adopted by
Most recently taken up by
- timwukp/agent-skills-best-practicetheir own version, first seen Sep 16, 2026
- yueheng-rgb/codex-factorytheir own version, first seen Sep 15, 2026
- anuragsarkar97/skillstheir own version, first seen Jun 24, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- yueheng-rgb/codex-factory★ 100same name
- timwukp/agent-skills-best-practice★ 12same name
- anuragsarkar97/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository1,129 other files it gives its agents.
- userinterface-wiki/AGENTS.mdAGENTS.md
- aaronontheweb-dotnet-skillsSkill
- ab-test-setupSkill
- acquiring-disk-image-with-dd-and-dcflddSkill
- Agent BrowserSkill
- agent-browserSkill
- agent-browserSkill
- agent-configurationSkill
- agent-email-cliSkill
- agent-evaluationSkill
- agentic-development-principlesSkill
- agentic-workflowSkill
- agent-toolsSkill
- ai-image-generationSkill
- ai-video-generationSkill
- algorithmic-artSkill
- analytics-trackingSkill
- analyzing-active-directory-acl-abuseSkill
- analyzing-android-malware-with-apktoolSkill
- analyzing-api-gateway-access-logsSkill
- analyzing-apt-group-with-mitre-navigatorSkill
- analyzing-azure-activity-logs-for-threatsSkill
- analyzing-bootkit-and-rootkit-samplesSkill
- analyzing-browser-forensics-with-hindsightSkill
- analyzing-campaign-attribution-evidenceSkill
- analyzing-certificate-transparency-for-phishingSkill
- analyzing-cloud-storage-access-patternsSkill
- analyzing-cobalt-strike-beacon-configurationSkill
- analyzing-cobaltstrike-malleable-c2-profilesSkill
- analyzing-cobalt-strike-malleable-profilesSkill
- analyzing-command-and-control-communicationSkill
- analyzing-cyber-kill-chainSkill
- analyzing-disk-image-with-autopsySkill
- analyzing-dns-logs-for-exfiltrationSkill
- analyzing-docker-container-forensicsSkill
- analyzing-email-headers-for-phishing-investigationSkill
- analyzing-ethereum-smart-contract-vulnerabilitiesSkill
- analyzing-golang-malware-with-ghidraSkill
- analyzing-heap-spray-exploitationSkill
- analyzing-indicators-of-compromiseSkill
- analyzing-ios-app-security-with-objectionSkill
- analyzing-kubernetes-audit-logsSkill
- analyzing-linux-audit-logs-for-intrusionSkill
- analyzing-linux-elf-malwareSkill
- analyzing-linux-kernel-rootkitsSkill
- analyzing-linux-system-artifactsSkill
- analyzing-lnk-file-and-jump-list-artifactsSkill
- analyzing-macro-malware-in-office-documentsSkill
- analyzing-malicious-pdf-with-peepdfSkill
- analyzing-malicious-url-with-urlscanSkill
- analyzing-malware-behavior-with-cuckoo-sandboxSkill
- analyzing-malware-family-relationships-with-malpediaSkill
- analyzing-malware-persistence-with-autorunsSkill
- analyzing-malware-sandbox-evasion-techniquesSkill
- analyzing-memory-dumps-with-volatilitySkill
- analyzing-memory-forensics-with-lime-and-volatilitySkill
- analyzing-mft-for-deleted-file-recoverySkill
- analyzing-network-covert-channels-in-malwareSkill
- analyzing-network-flow-data-with-netflowSkill
- analyzing-network-packets-with-scapySkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Plan for growth: - consider partitioning early
- Distinctive: line 239
Create indexes based on queries: not assumptions
- Distinctive: line 240
Use ENUM types sparingly: - prefer check constraints
- Distinctive: line 241
Plan for soft deletes: if business requires audit trail
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Schema Design
Core Principles
- Normalize first, denormalize for performance
- Use appropriate data types - smallest type that fits
- Index strategically - based on query patterns
- Plan for growth - consider partitioning early
Naming Conventions
-- Tables: plural, snake_case
users, order_items, user_addresses
-- Columns: snake_case
first_name, created_at, is_active
-- Primary keys: id
id SERIAL PRIMARY KEY
-- Foreign keys: singular_table_id
user_id REFERENCES users(id)
-- Indexes: idx_table_column(s)
CREATE INDEX idx_users_email ON users(email);
-- Constraints: chk_/uq_/fk_ prefix
CONSTRAINT uq_users_email UNIQUE (email)
CONSTRAINT chk_orders_amount CHECK (amount > 0)Common Patterns
Users Table
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
name VARCHAR(100) NOT NULL,
role VARCHAR(20) DEFAULT 'user' CHECK (role IN ('user', 'admin', 'moderator')),
is_active BOOLEAN DEFAULT true,
email_verified_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_role ON users(role) WHERE is_active = true;One-to-Many Relationship
CREATE TABLE posts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title VARCHAR(255) NOT NULL,
content TEXT,
status VARCHAR(20) DEFAULT 'draft',
published_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX idx_posts_user_id ON posts(user_id);
CREATE INDEX idx_posts_status_published ON posts(status, published_at DESC)
WHERE status = 'published';Many-to-Many Relationship
CREATE TABLE tags (
id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL UNIQUE,
slug VARCHAR(50) NOT NULL UNIQUE
);
CREATE TABLE post_tags (
post_id UUID REFERENCES posts(id) ON DELETE CASCADE,
tag_id INTEGER REFERENCES tags(id) ON DELETE CASCADE,
PRIMARY KEY (post_id, tag_id)
);
CREATE INDEX idx_post_tags_tag_id ON post_tags(tag_id);Polymorphic Associations
-- Using separate tables (preferred)
CREATE TABLE post_comments (
id UUID PRIMARY KEY,
post_id UUID REFERENCES posts(id),
content TEXT NOT NULL,
user_id UUID REFERENCES users(id)
);
CREATE TABLE image_comments (
id UUID PRIMARY KEY,
image_id UUID REFERENCES images(id),
content TEXT NOT NULL,
user_id UUID REFERENCES users(id)
);
-- Alternative: Single table with type column
CREATE TABLE comments (
id UUID PRIMARY KEY,
commentable_type VARCHAR(50) NOT NULL,
commentable_id UUID NOT NULL,
content TEXT NOT NULL,
user_id UUID REFERENCES users(id),
CONSTRAINT uq_comments_target UNIQUE (commentable_type, commentable_id, id)
);Drizzle ORM Schema
import { pgTable, uuid, varchar, text, timestamp, boolean, index } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
email: varchar('email', { length: 255 }).notNull().unique(),
name: varchar('name', { length: 100 }).notNull(),
passwordHash: varchar('password_hash', { length: 255 }).notNull(),
isActive: boolean('is_active').default(true),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(),
}, (table) => ({
emailIdx: index('idx_users_email').on(table.email),
}));
export const posts = pgTable('posts', {
id: uuid('id').primaryKey().defaultRandom(),
userId: uuid('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
title: varchar('title', { length: 255 }).notNull(),
content: text('content'),
status: varchar('status', { length: 20 }).default('draft'),
publishedAt: timestamp('published_at', { withTimezone: true }),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
});
export const usersRelations = relations(users, ({ many }) => ({
posts: many(posts),
}));
export const postsRelations = relations(posts, ({ one }) => ({
author: one(users, {
fields: [posts.userId],
references: [users.id],
}),
}));Indexing Strategies
-- Single column index
CREATE INDEX idx_users_email ON users(email);
-- Composite index (order matters!)
CREATE INDEX idx_posts_user_status ON posts(user_id, status);
-- Partial index (smaller, faster)
CREATE INDEX idx_posts_published ON posts(published_at DESC)
WHERE status = 'published';
-- Expression index
CREATE INDEX idx_users_email_lower ON users(LOWER(email));
-- JSONB index
CREATE INDEX idx_users_metadata ON users USING GIN(metadata);Soft Deletes
CREATE TABLE posts (
id UUID PRIMARY KEY,
-- other columns...
deleted_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Query active records
SELECT * FROM posts WHERE deleted_at IS NULL;
-- Partial index for performance
CREATE INDEX idx_posts_active ON posts(created_at DESC)
WHERE deleted_at IS NULL;Audit Trail
CREATE TABLE audit_logs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
table_name VARCHAR(100) NOT NULL,
record_id UUID NOT NULL,
action VARCHAR(20) NOT NULL, -- INSERT, UPDATE, DELETE
old_data JSONB,
new_data JSONB,
user_id UUID REFERENCES users(id),
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Trigger function
CREATE OR REPLACE FUNCTION audit_trigger_func()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO audit_logs (table_name, record_id, action, old_data, new_data, user_id)
VALUES (
TG_TABLE_NAME,
COALESCE(NEW.id, OLD.id),
TG_OP,
CASE WHEN TG_OP != 'INSERT' THEN row_to_json(OLD) END,
CASE WHEN TG_OP != 'DELETE' THEN row_to_json(NEW) END,
current_setting('app.current_user_id', true)::uuid
);
RETURN COALESCE(NEW, OLD);
END;
$$ LANGUAGE plpgsql;Best Practices
- Always use UUIDs for public-facing IDs
- Add timestamps (created_at, updated_at) to all tables
- Use foreign key constraints for referential integrity
- Create indexes based on queries not assumptions
- Use ENUM types sparingly - prefer check constraints
- Plan for soft deletes if business requires audit trail
- Use transactions for multi-table operations
- Partition large tables by time or category
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

