2019-07-31 18:38:48 +00:00
|
|
|
|
|
|
|
exports.up = function(knex) {
|
|
|
|
return knex.schema
|
|
|
|
|
|
|
|
.createTable('users', tbl => {
|
|
|
|
tbl
|
|
|
|
.increments();
|
|
|
|
tbl
|
|
|
|
.string('email')
|
|
|
|
.notNullable()
|
|
|
|
.unique();
|
|
|
|
tbl
|
|
|
|
.string('username')
|
|
|
|
.notNullable()
|
|
|
|
.unique();
|
|
|
|
tbl
|
|
|
|
.string('password')
|
|
|
|
.notNullable();
|
|
|
|
})
|
|
|
|
|
|
|
|
.createTable('sessions', tbl => {
|
|
|
|
tbl
|
|
|
|
.increments();
|
|
|
|
tbl
|
|
|
|
.integer('user_id')
|
|
|
|
.unsigned()
|
|
|
|
.notNullable()
|
|
|
|
.references('users.id')
|
|
|
|
.onUpdate('CASCADE')
|
|
|
|
.onDelete('CASCADE');
|
|
|
|
tbl
|
|
|
|
.datetime('bed_time')
|
|
|
|
.notNullable();
|
|
|
|
tbl
|
|
|
|
.datetime('wake_time');
|
|
|
|
tbl
|
2019-08-01 14:25:44 +00:00
|
|
|
.integer('wake_mood')
|
2019-07-31 18:38:48 +00:00
|
|
|
.unsigned();
|
|
|
|
tbl
|
2019-08-01 14:25:44 +00:00
|
|
|
.integer('day_mood')
|
|
|
|
.unsigned();
|
|
|
|
tbl
|
|
|
|
.integer('bed_tiredness')
|
2019-07-31 18:38:48 +00:00
|
|
|
.unsigned();
|
|
|
|
})
|
|
|
|
|
|
|
|
.createTable('dailyAverages', tbl => {
|
|
|
|
tbl
|
|
|
|
.increments();
|
|
|
|
tbl
|
2019-08-01 14:25:44 +00:00
|
|
|
.integer('session_id')
|
2019-07-31 18:38:48 +00:00
|
|
|
.unsigned()
|
|
|
|
.notNullable()
|
2019-08-01 14:25:44 +00:00
|
|
|
.references('sessions.id')
|
2019-07-31 18:38:48 +00:00
|
|
|
.onUpdate('CASCADE')
|
|
|
|
.onDelete('CASCADE');
|
|
|
|
tbl
|
2019-08-01 14:25:44 +00:00
|
|
|
.integer('user_id')
|
|
|
|
.unsigned()
|
2019-07-31 18:38:48 +00:00
|
|
|
.notNullable()
|
2019-08-01 14:25:44 +00:00
|
|
|
.references('users.id')
|
2019-07-31 18:38:48 +00:00
|
|
|
.onUpdate('CASCADE')
|
|
|
|
.onDelete('CASCADE');
|
|
|
|
tbl
|
|
|
|
.integer('sleep_duration')
|
|
|
|
.unsigned();
|
|
|
|
tbl
|
|
|
|
.float('average_mood');
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.down = function(knex) {
|
|
|
|
return knex.schema
|
|
|
|
.dropTableIfExists('dailyAverages')
|
|
|
|
.dropTableIfExists('sessions')
|
|
|
|
.dropTableIfExists('users');
|
|
|
|
};
|