diff --git a/src/db/migrations/20251213215048_create_remaining_tables.js b/src/db/migrations/20240730120000_create_initial_schema.js similarity index 71% rename from src/db/migrations/20251213215048_create_remaining_tables.js rename to src/db/migrations/20240730120000_create_initial_schema.js index 0a00635..376371d 100644 --- a/src/db/migrations/20251213215048_create_remaining_tables.js +++ b/src/db/migrations/20240730120000_create_initial_schema.js @@ -1,5 +1,28 @@ exports.up = function(knex) { return knex.schema + .createTable('sucursales', function(table) { + table.increments('id').primary(); + table.string('nombre', 255).notNullable(); + table.text('direccion'); + table.timestamps(true, true); + }) + .createTable('usuarios', function(table) { + table.increments('id').primary(); + table.string('nombre', 255).notNullable(); + table.string('email', 255).unique().notNullable(); + table.string('password_hash', 255).notNullable(); + table.string('rol', 50).notNullable(); + table.timestamps(true, true); + }) + .createTable('socias', function(table) { + table.increments('id').primary(); + table.string('nombre', 255).notNullable(); + table.string('apellido', 255).notNullable(); + table.date('fecha_ingreso').notNullable(); + table.integer('id_sucursal').unsigned().references('id').inTable('sucursales'); + table.boolean('activo').defaultTo(true); + table.timestamps(true, true); + }) .createTable('vacaciones', function(table) { table.increments('id').primary(); table.integer('id_socia').unsigned().references('id').inTable('socias'); @@ -35,14 +58,6 @@ exports.up = function(knex) { table.text('descripcion'); table.timestamps(true, true); }) - .createTable('usuarios', function(table) { - table.increments('id').primary(); - table.string('nombre', 255).notNullable(); - table.string('email', 255).unique().notNullable(); - table.string('password_hash', 255).notNullable(); - table.string('rol', 50).notNullable(); - table.timestamps(true, true); - }) .createTable('permisos_granulares', function(table) { table.increments('id').primary(); table.integer('id_usuario').unsigned().references('id').inTable('usuarios'); @@ -55,10 +70,12 @@ exports.up = function(knex) { exports.down = function(knex) { return knex.schema - .dropTable('permisos_granulares') - .dropTable('usuarios') - .dropTable('configuraciones') - .dropTable('eventos') - .dropTable('permisos') - .dropTable('vacaciones'); + .dropTableIfExists('permisos_granulares') + .dropTableIfExists('vacaciones') + .dropTableIfExists('permisos') + .dropTableIfExists('eventos') + .dropTableIfExists('configuraciones') + .dropTableIfExists('socias') + .dropTableIfExists('usuarios') + .dropTableIfExists('sucursales'); }; diff --git a/src/db/migrations/20251213214742_initial_schema.js b/src/db/migrations/20251213214742_initial_schema.js deleted file mode 100644 index 4fd2487..0000000 --- a/src/db/migrations/20251213214742_initial_schema.js +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @param { import("knex").Knex } knex - * @returns { Promise } - */ -exports.up = function(knex) { - return knex.schema - .createTable('branches', function (table) { - table.string('id').primary(); - table.string('name', 255).notNullable(); - table.string('address', 255); - }) - .createTable('users', function (table) { - table.string('id').primary(); - table.string('username', 255).notNullable().unique(); - table.string('role', 50).notNullable(); - table.jsonb('permissions'); - table.timestamps(true, true); - }) - .createTable('employees', function (table) { - table.string('id').primary(); - table.string('firstName', 255).notNullable(); - table.string('lastName', 255).notNullable(); - table.string('email', 255).notNullable().unique(); - table.timestamp('hireDate').notNullable(); - table.string('branchId').references('id').inTable('branches'); - table.boolean('isActive').defaultTo(true); - table.timestamps(true, true); - }) - .createTable('vacations', function (table) { - table.string('id').primary(); - table.string('employeeId').notNullable().references('id').inTable('employees'); - table.date('startDate').notNullable(); - table.date('endDate').notNullable(); - table.integer('daysUsed').notNullable(); - table.string('status', 50).notNullable().defaultTo('PENDING'); - table.integer('cycleYear').notNullable(); - table.timestamp('requestedAt').defaultTo(knex.fn.now()); - table.string('approvedBy').references('id').inTable('users'); - table.timestamp('approvedAt'); - }) - .createTable('permissions', function (table) { - table.string('id').primary(); - table.string('employeeId').notNullable().references('id').inTable('employees'); - table.date('permissionDate').notNullable(); - table.integer('hours'); - table.string('reason', 255); - table.string('status', 50).notNullable().defaultTo('PENDING'); - table.timestamp('requestedAt').defaultTo(knex.fn.now()); - }); -}; - -/** - * @param { import("knex").Knex } knex - * @returns { Promise } - */ -exports.down = function(knex) { - return knex.schema - .dropTable('permissions') - .dropTable('vacations') - .dropTable('employees') - .dropTable('users') - .dropTable('branches'); -}; diff --git a/src/db/migrations/20251213215023_create_sucursales_table.js b/src/db/migrations/20251213215023_create_sucursales_table.js deleted file mode 100644 index 0724082..0000000 --- a/src/db/migrations/20251213215023_create_sucursales_table.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.up = function(knex) { - return knex.schema.createTable('sucursales', function(table) { - table.increments('id').primary(); - table.string('nombre', 255).notNullable(); - table.text('direccion'); - table.timestamps(true, true); - }); -}; - -exports.down = function(knex) { - return knex.schema.dropTable('sucursales'); -}; diff --git a/src/db/migrations/20251213215035_create_socias_table.js b/src/db/migrations/20251213215035_create_socias_table.js deleted file mode 100644 index 671231e..0000000 --- a/src/db/migrations/20251213215035_create_socias_table.js +++ /dev/null @@ -1,15 +0,0 @@ -exports.up = function(knex) { - return knex.schema.createTable('socias', function(table) { - table.increments('id').primary(); - table.string('nombre', 255).notNullable(); - table.string('apellido', 255).notNullable(); - table.date('fecha_ingreso').notNullable(); - table.integer('id_sucursal').unsigned().references('id').inTable('sucursales'); - table.boolean('activo').defaultTo(true); - table.timestamps(true, true); - }); -}; - -exports.down = function(knex) { - return knex.schema.dropTable('socias'); -};