Skip to content
Colin Eckert edited this page Feb 13, 2021 · 8 revisions

Postgres Database Schema

users

column name data type details
id integer not null, primary key
email string not null, indexed, unique
full_name string
password_digest string not null
session_token string not null, indexed, unique
created_at datetime not null
updated_at datetime not null
  • index on email, unique: true
  • index on session_token, unique: true
  • has many notes through notebooks

notebooks

column name data type details
id integer not null, primary key
name string not null, unique, indexed
author_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • index on [:name, :author_id], unique: true

notes

column name data type details
id integer not null, primary key
title string
body text not null
notebook_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • notebook_id references notebooks
  • index on notebook_id
  • has many tags through note_tags

tags

column name data type details
id integer not null, primary key
name string not null, unique, indexed
author_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • index on [:name, :author_id], unique: true
  • has many notes through note_tags

note_tags

column name data type details
id integer not null, primary key
note_id integer not null, indexed, foreign key
tag_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • note_id references notes
  • tag_id references tags
  • index on [:note_id, :tag_id], unique: true
Clone this wiki locally