Blog App (MySQL with Drizzle ORM)
This document outlines the MySQL database schema for a sample blog application. The schema is designed to be efficient, scalable, and easy to understand. We use Drizzle ORM for defining our data models with TypeScript.
The core of our application revolves around six main tables: User, Post, Category, Comment, PostLike, and CommentLike.
Installation Guide
To add these schemas to your project, run:
npx servercn-cli add schema blog-appIf you install schema individually, the relationships between them won't be automatic—you'll need to implement them manually.
1. User Schema
The User schema stores essential information about blog authors and administrators, including authentication details and profile information.
Path: src/drizzle/schemas/user.schema.ts
Installation
npx servercn-cli add schema blog-app/user2. Post Schema
The Post schema stores blog posts with support for titles, content, excerpts, featured images, and publication status.
Path: src/drizzle/schemas/post.schema.ts
Installation
npx servercn-cli add schema blog-app/post3. Category Schema
The Category schema organizes blog posts into hierarchical categories with names, slugs, and descriptions.
Path: src/drizzle/schemas/category.schema.ts
Installation
npx servercn-cli add schema blog-app/category4. Comment Schema
The Comment schema enables user engagement through comments on blog posts, with support for nested replies.
Path: src/drizzle/schemas/comment.schema.ts
Installation
npx servercn-cli add schema blog-app/comment5. Post Like Schema
The PostLike schema tracks user likes on blog posts with a composite unique index.
Path: src/drizzle/schemas/post-like.schema.ts
Installation
npx servercn-cli add schema blog-app/post-like6. Comment Like Schema
The CommentLike schema tracks user likes on comments with a composite unique index.
Path: src/drizzle/schemas/comment-like.schema.ts
Installation
npx servercn-cli add schema blog-app/comment-like7. Export all schemas
All database schemas must be re-exported from a single entry point. This allows Drizzle to load every table definition from one file during migration generation.
File Path: src/drizzle/index.ts
8. drizzle.config.ts
Create a drizzle.config.ts file at the project root.
This file defines how Drizzle connects to the database and where it should read schemas and write migrations.
File Path: drizzle.config.ts