SchemaSeed Guides

Sample blog database

A blog needs an author, a post that belongs to that author, and a comment that belongs to that post. This sample uses UUID primary keys. Each author_id and post_id is copied from a parent row, so the inserts can load with the foreign keys turned on.

CREATE TABLE authors (
  id UUID PRIMARY KEY,
  email VARCHAR(255) NOT NULL,
  full_name VARCHAR(120),
  bio TEXT
);

CREATE TABLE posts (
  id UUID PRIMARY KEY,
  author_id UUID NOT NULL REFERENCES authors(id),
  title VARCHAR(200) NOT NULL,
  slug VARCHAR(200),
  body TEXT,
  published BOOLEAN,
  created_at TIMESTAMP
);

CREATE TABLE comments (
  id UUID PRIMARY KEY,
  post_id UUID NOT NULL REFERENCES posts(id),
  author_name VARCHAR(120),
  body TEXT,
  created_at TIMESTAMP
);

Author names and emails look like people. Titles, slugs, and comment text are sentences. published is true or false. The SQL file inserts authors, then posts, then comments.

Open the blog sample

For a store, use the ecommerce sample. For organizations and members, use the company sample.