Skip to content

Blog Schema

A full blog schema demonstrating authentication, content management, and relationships.

schemas/auth/user.js
export default table({
id: col.id(),
email: col.email().unique(),
username: col.username().unique(),
password: col.password_hash(),
is_active: col.flag(true),
}).timestamps();
schemas/blog/post.js
export default table({
id: col.id(),
author: col.belongs_to("auth.user"),
title: col.title(),
slug: col.slug().unique(),
body: col.body(),
status: col.enum(["draft", "published", "archived"]).default("draft"),
published_at: col.datetime().optional(),
})
.timestamps()
.soft_delete();

Self-referential replies allow nested comment threads.

schemas/blog/comment.js
export default table({
id: col.id(),
post: col.belongs_to("blog.post"),
author: col.belongs_to("auth.user"),
parent: col.belongs_to("blog.comment").optional(),
body: col.text(),
is_approved: col.flag(false),
})
.timestamps()
.soft_delete();

Many-to-many relationship with posts for flexible categorization.

schemas/blog/tag.js
export default table({
id: col.id(),
name: col.name().unique(),
slug: col.slug().unique(),
posts: col.many_to_many("blog.post"),
}).timestamps();