78 lines
1.3 KiB
JavaScript
78 lines
1.3 KiB
JavaScript
|
|
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
|
|
.integer('wake_mood')
|
|
.unsigned();
|
|
tbl
|
|
.integer('day_mood')
|
|
.unsigned();
|
|
tbl
|
|
.integer('bed_tiredness')
|
|
.unsigned();
|
|
})
|
|
|
|
.createTable('dailyAverages', tbl => {
|
|
tbl
|
|
.increments();
|
|
tbl
|
|
.integer('session_id')
|
|
.unsigned()
|
|
.notNullable()
|
|
.references('sessions.id')
|
|
.onUpdate('CASCADE')
|
|
.onDelete('CASCADE');
|
|
tbl
|
|
.integer('user_id')
|
|
.unsigned()
|
|
.notNullable()
|
|
.references('users.id')
|
|
.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');
|
|
};
|