Skip to content

Database Schema

Shawn edited this page May 12, 2019 · 4 revisions

Database Schema

users (Normalized)

Column Name Date Type Content
id integer primary key, auto increment
username string not null
first_name string
password_digest string not null
session_token string not null
  • index: username, unique

users (Denormalized)

const UserSchema = new Schema({
    username: {
      type: String,
      required: true
    },
    first_name: {
      type: String,
      required: true
    },
    children: {
      type: Array,
      required: true
    },
    password_digest: {
      type: String,
      required: true
    },
    date: {
      type: Date,
      default: Date.now
    }
})

chores (Normalized)

Column Name Date Type Content
id integer primary key, auto increment
title string not null
body text not null
amount float not null
deadline date
parent_id integer not null
child_id integer
repeating string default: one-time
priority boolean default: false
  • index: child_id, parent_id
  • Foreign Key: child_id belongs to users
  • Foreign Key: parent_id belongs to users

chores (Denormalized)

const ChoreSchema = new Schema({
    title: {
      type: String,
      required: true
    },
    body: {
      type: String,
      required: true
    },
    amount: {
      type: Numbers,
      required: true
    },
    deadline: {
      type: Date
    },
    parent: {
      type: Schema.Types.ObjectId
      ref: 'users'
    },
    child: {
      type: Schema.Types.ObjectId
      ref: 'users'
    },
    repeating: {
      type: String,
      default: "one-time"
    },
    priority: {
      type: Boolean,
      default: false
    }
    date: {
      type: Date,
      default: Date.now
    }
})

family (Normalized)

Column Name Date Type Content
id integer primary key, auto increment
parent_id integer not null
child_id string not null
balance_owed float not null
  • index: parent_id, child_id
  • Foreign Key: parent_id belongs to users
  • Foreign Key: child_id belongs to users

family (Denormalized)

Not needed


payouts (Normalized)

Column Name Date Type Content
id integer primary key, auto increment
child_id integer not null
amount float not null
  • index: child_id
  • Foreign Key: child_id belongs to users

payouts (Denormalized)

const PayoutSchema = new Schema({
    parent: {
      type: Schema.Types.ObjectId,
      required: true
    },
    child: {
      type: Schema.Types.ObjectId,
      required: true
    },
    amount: {
      type: Numbers,
      required: true
    },
    date: {
      type: Date,
      default: Date.now
    }

Clone this wiki locally