diff --git a/.gitignore b/.gitignore index dffbe0d..751451f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules server/.env +.env +``` diff --git a/lib/migrations/0-favorites.js b/lib/migrations/0-favorites.js deleted file mode 100644 index fa0c319..0000000 --- a/lib/migrations/0-favorites.js +++ /dev/null @@ -1,19 +0,0 @@ -// Migration pour créer la table des favoris -'use strict'; - -module.exports = { - async up(knex) { - await knex.schema.createTable('favorites', (table) => { - table.integer('user_id').unsigned().notNullable(); - table.integer('movie_id').unsigned().notNullable(); - table.primary(['user_id', 'movie_id']); - table.foreign('user_id').references('id').inTable('user'); - table.foreign('movie_id').references('id').inTable('movie'); - }); - }, - - async down(knex) { - await knex.schema.dropTable('favorites'); - } - -} \ No newline at end of file diff --git a/lib/migrations/0-user.js b/lib/migrations/0-user.js deleted file mode 100644 index 3d8ae90..0000000 --- a/lib/migrations/0-user.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -module.exports = { - - async up(knex) { - - //update table User for role - await knex.schema.table('user', (table) => { - - table.string('role').notNullable().defaultTo('user'); - }); - }, - - async down(knex) { - - //update table User for role - await knex.schema.table('user', (table) => { - - table.dropColumn('role'); - }); - } -}; diff --git a/lib/migrations/1-user.js b/lib/migrations/1-user.js deleted file mode 100644 index 3d8ae90..0000000 --- a/lib/migrations/1-user.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -module.exports = { - - async up(knex) { - - //update table User for role - await knex.schema.table('user', (table) => { - - table.string('role').notNullable().defaultTo('user'); - }); - }, - - async down(knex) { - - //update table User for role - await knex.schema.table('user', (table) => { - - table.dropColumn('role'); - }); - } -}; diff --git a/lib/migrations/2-user.js b/lib/migrations/2-user.js deleted file mode 100644 index 8fbcc55..0000000 --- a/lib/migrations/2-user.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -module.exports = { - - async up(knex) { - - // Add the "scope" field to the "user" table - await knex.schema.table('user', (table) => { - table.dropColumn('scope'); // Remove the "role" field - table.string('scope').notNullable().defaultTo('user'); - - }); - }, - - async down(knex) { - - // Revert the changes made in the "up" function - await knex.schema.table('user', (table) => { - table.dropColumn('scope'); - table.string('scope').notNullable().defaultTo('user'); - }); - } -}; diff --git a/lib/migrations/3-user.js b/lib/migrations/3-user.js deleted file mode 100644 index 58dba54..0000000 --- a/lib/migrations/3-user.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -module.exports = { - - async up(knex) { - - // Add the "scope" field to the "user" table - await knex.schema.table('user', (table) => { - table.dropColumn('scope'); // Remove the "role" field - - }); - }, - - async down(knex) { - - // Revert the changes made in the "up" function - await knex.schema.table('user', (table) => { - table.string('scope').notNullable().defaultTo('user'); - }); - } -}; diff --git a/lib/migrations/4-user.js b/lib/migrations/4-user.js deleted file mode 100644 index 4a63ce5..0000000 --- a/lib/migrations/4-user.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -module.exports = { - - async up(knex) { - - // Add the "scope" field to the "user" table - await knex.schema.table('user', (table) => { - table.string('scope').notNullable().defaultTo('user'); - - }); - }, - - async down(knex) { - - // Revert the changes made in the "up" function - await knex.schema.table('user', (table) => { - table.dropColumn('scope'); - }); - } -}; diff --git a/lib/migrations/all_tables.js b/lib/migrations/all_tables.js new file mode 100644 index 0000000..974a3f2 --- /dev/null +++ b/lib/migrations/all_tables.js @@ -0,0 +1,43 @@ +'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'); + } +};