Skip to content
Micah Jaffe edited this page Dec 11, 2018 · 11 revisions

Database Schema

users

column name data type details
id integer not null, primary key
username string not null, indexed, unique
email string not null, indexed, unique
password_digest string not null
session_token string not null, indexed, unique
created_at datetime not null
updated_at datetime not null

notebooks

column name data type details
id integer not null, primary key
name string not null, default: Untitled, indexed
created_at datetime not null
updated_at datetime not null
user_id integer not null, foreign key
  • user_id references users table
  • name index should be unique within user scope, i.e. index on [name, user_id] unique

notes

column name data type details
id integer not null, primary key
title string not null, default: Untitled, indexed
body text
created_at datetime not null
updated_at datetime not null
notebook_id integer not null, foreign key
user_id integer not null, foreign key
  • notebook_id references notebooks table. All notes must belong to a notebook. user_id references the users table.

note_tags

column name data type details
id integer not null, primary key
note_id integer not null, foreign key
tag_id integer not null, foreign key
created_at datetime not null
updated_at datetime not null
  • note_tags is a joins table for the many-to-many relationship between notes and tags. A note can have zero or more tags. A tag can have zero or more notes (although typically will have at least one). Tags should be unique with the scope of notes and vice-versa, so there should be an index on [note_id, tag_id] unique.

tags

column name data type details
id integer not null, primary key
name string not null, indexed
created_at datetime not null
updated_at datetime not null
Clone this wiki locally