From 09e5b2f76fc3384aec25dd7bdd93e0bca2ce3485 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Mon, 16 Aug 2021 22:32:08 +0200 Subject: [PATCH] Rework migrations schemes --- database/migrations/1608409476823_locations.ts | 6 +++--- database/migrations/1608415261417_projects.ts | 13 +++++++++---- database/migrations/1618661863952_forms.ts | 8 ++++---- database/migrations/1625078903131_users.ts | 5 ++++- database/migrations/1625078908619_api_tokens.ts | 6 +++++- .../1625146912533_guestbook_messages.ts | 2 +- .../migrations/1628110081266_translations.ts | 2 +- database/migrations/1628110400158_projects.ts | 17 ----------------- database/migrations/1628759408774_announces.ts | 4 ++-- database/migrations/1628936238073_skills.ts | 4 ++-- .../migrations/1628945210540_informations.ts | 2 +- 11 files changed, 32 insertions(+), 37 deletions(-) delete mode 100644 database/migrations/1628110400158_projects.ts diff --git a/database/migrations/1608409476823_locations.ts b/database/migrations/1608409476823_locations.ts index de1d485..0b44e62 100644 --- a/database/migrations/1608409476823_locations.ts +++ b/database/migrations/1608409476823_locations.ts @@ -6,9 +6,9 @@ export default class Locations extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { table.increments('id').primary() - table.string('place') - table.string('left') - table.date('since') + table.string('place').notNullable() + table.string('left').notNullable() + table.date('since').notNullable() table.timestamps(true, true) }) } diff --git a/database/migrations/1608415261417_projects.ts b/database/migrations/1608415261417_projects.ts index 85919de..ec8e071 100644 --- a/database/migrations/1608415261417_projects.ts +++ b/database/migrations/1608415261417_projects.ts @@ -6,10 +6,15 @@ export default class Projects extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { table.increments('id').primary() - table.string('name') - table.string('description') - table.string('url') - table.integer('progress') + table.string('name').notNullable() + table.string('description').notNullable() + table.string('url').notNullable() + table.integer('progress').notNullable() + table + .integer('file_id') + .unsigned() + .references('files.id') + .onDelete('CASCADE') table.timestamps(true, true) }) } diff --git a/database/migrations/1618661863952_forms.ts b/database/migrations/1618661863952_forms.ts index d59a0ed..5f472c8 100644 --- a/database/migrations/1618661863952_forms.ts +++ b/database/migrations/1618661863952_forms.ts @@ -6,10 +6,10 @@ export default class Forms extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { table.increments('id').primary() - table.string('name') - table.string('email') - table.string('subject') - table.string('content') + table.string('name').notNullable() + table.string('email').notNullable() + table.string('subject').notNullable() + table.string('content').notNullable() table.timestamps(true, true) }) } diff --git a/database/migrations/1625078903131_users.ts b/database/migrations/1625078903131_users.ts index ba44cb0..1f4d68c 100644 --- a/database/migrations/1625078903131_users.ts +++ b/database/migrations/1625078903131_users.ts @@ -9,7 +9,10 @@ export default class Users extends BaseSchema { table.increments('id').primary() table.string('username', 255).notNullable() table.string('email', 255).notNullable() - table.string('password', 180).defaultTo(this.randomPassword()).notNullable() + table + .string('password', 180) + .defaultTo(this.randomPassword()) + .notNullable() table.boolean('is_confirmed').defaultTo(false).notNullable() table.string('remember_me_token').defaultTo(null).nullable() table.string('confirmation_token').defaultTo(null).nullable() diff --git a/database/migrations/1625078908619_api_tokens.ts b/database/migrations/1625078908619_api_tokens.ts index 96fd16c..5278eb3 100644 --- a/database/migrations/1625078908619_api_tokens.ts +++ b/database/migrations/1625078908619_api_tokens.ts @@ -6,7 +6,11 @@ export default class ApiTokens extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { table.increments('id').primary() - table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE') + table.integer('user_id') + .unsigned() + .references('id') + .inTable('users') + .onDelete('CASCADE') table.string('name').notNullable() table.string('type').notNullable() table.string('token', 64).notNullable() diff --git a/database/migrations/1625146912533_guestbook_messages.ts b/database/migrations/1625146912533_guestbook_messages.ts index 0e8bd0b..8ef518d 100644 --- a/database/migrations/1625146912533_guestbook_messages.ts +++ b/database/migrations/1625146912533_guestbook_messages.ts @@ -11,7 +11,7 @@ export default class GuestbookMessages extends BaseSchema { .unsigned() .references('users.id') .onDelete('CASCADE') - table.text('message') + table.text('message').notNullable() table.timestamps(true, true) }) } diff --git a/database/migrations/1628110081266_translations.ts b/database/migrations/1628110081266_translations.ts index 7a80bfc..218bec2 100644 --- a/database/migrations/1628110081266_translations.ts +++ b/database/migrations/1628110081266_translations.ts @@ -5,7 +5,7 @@ export default class Translations extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { - table.increments('id') + table.increments('id').primary() table.string('code').notNullable() table.string('french').defaultTo('Traduction manquante') table.string('english').defaultTo('Missing translation') diff --git a/database/migrations/1628110400158_projects.ts b/database/migrations/1628110400158_projects.ts deleted file mode 100644 index 6e4cc0e..0000000 --- a/database/migrations/1628110400158_projects.ts +++ /dev/null @@ -1,17 +0,0 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema' - -export default class Projects extends BaseSchema { - protected tableName = 'projects' - - public async up () { - this.schema.table(this.tableName, (table) => { - table.integer('file_id').unsigned().references('files.id').onDelete('CASCADE') - }) - } - - public async down () { - this.schema.table(this.tableName, (table) => { - table.dropColumn('file_id') - }) - } -} diff --git a/database/migrations/1628759408774_announces.ts b/database/migrations/1628759408774_announces.ts index f24b512..01994cd 100644 --- a/database/migrations/1628759408774_announces.ts +++ b/database/migrations/1628759408774_announces.ts @@ -5,8 +5,8 @@ export default class Announces extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { - table.increments('id') - table.string('color') + table.increments('id').primary() + table.string('color').notNullable() table.string('hover_color') table .integer('translation_id') diff --git a/database/migrations/1628936238073_skills.ts b/database/migrations/1628936238073_skills.ts index 3e54d20..56195cb 100644 --- a/database/migrations/1628936238073_skills.ts +++ b/database/migrations/1628936238073_skills.ts @@ -5,8 +5,8 @@ export default class Skills extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { - table.increments('id') - table.string('name') + table.increments('id').primary() + table.string('name').notNullable() table .integer('file_id') .unsigned() diff --git a/database/migrations/1628945210540_informations.ts b/database/migrations/1628945210540_informations.ts index 9cfbd47..01bfd41 100644 --- a/database/migrations/1628945210540_informations.ts +++ b/database/migrations/1628945210540_informations.ts @@ -5,7 +5,7 @@ export default class Informations extends BaseSchema { public async up () { this.schema.createTable(this.tableName, (table) => { - table.increments('id') + table.increments('id').primary() table.integer('age').notNullable() table .integer('translation_id')