44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
module.exports = {
|
||
|
async up(knex) {
|
||
|
await knex.schema.createTable('user', (table) => {
|
||
|
table.increments('id').primary();
|
||
|
table.string('scope').notNullable().defaultTo('user');
|
||
|
table.string('username').notNullable();
|
||
|
table.string('firstName').notNullable();
|
||
|
table.string('lastName').notNullable();
|
||
|
table.string('email').notNullable();
|
||
|
table.string('password').notNullable();
|
||
|
table.dateTime('createdAt').notNullable().defaultTo(knex.fn.now());
|
||
|
table.dateTime('updatedAt').notNullable().defaultTo(knex.fn.now());
|
||
|
});
|
||
|
|
||
|
await knex.schema.createTable('movie', (table) => {
|
||
|
table.increments('id').primary();
|
||
|
table.string('title').notNullable();
|
||
|
table.text('description').notNullable();
|
||
|
table.date('releaseDate').notNullable();
|
||
|
table.string('director').notNullable();
|
||
|
table.dateTime('createdAt').notNullable().defaultTo(knex.fn.now());
|
||
|
table.dateTime('updatedAt').notNullable().defaultTo(knex.fn.now());
|
||
|
});
|
||
|
|
||
|
await knex.schema.createTable('favorites', (table) => {
|
||
|
table.increments('id').primary();
|
||
|
table.integer('user_id').unsigned().notNullable();
|
||
|
table.integer('movie_id').unsigned().notNullable();
|
||
|
table.foreign('user_id').references('user.id');
|
||
|
table.foreign('movie_id').references('movie.id');
|
||
|
table.dateTime('createdAt').notNullable().defaultTo(knex.fn.now());
|
||
|
table.dateTime('updatedAt').notNullable().defaultTo(knex.fn.now());
|
||
|
});
|
||
|
},
|
||
|
|
||
|
async down(knex) {
|
||
|
await knex.schema.dropTableIfExists('favorites');
|
||
|
await knex.schema.dropTableIfExists('movie');
|
||
|
await knex.schema.dropTableIfExists('user');
|
||
|
}
|
||
|
};
|