Modified migrations

master
Cemal Odabasioglu 2024-02-14 11:54:35 +01:00
parent bee15d8b5a
commit f9aa32926a
8 changed files with 45 additions and 128 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
node_modules node_modules
server/.env server/.env
.env
```

View File

@ -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');
}
}

View File

@ -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');
});
}
};

View File

@ -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');
});
}
};

View File

@ -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');
});
}
};

View File

@ -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');
});
}
};

View File

@ -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');
});
}
};

View File

@ -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');
}
};