/** * Missing Fleet Tables Migration * Adds fleet-related tables that were missing from previous migrations */ exports.up = function(knex) { return knex.schema // Create fleets table .createTable('fleets', (table) => { table.increments('id').primary(); table.integer('player_id').notNullable().references('players.id').onDelete('CASCADE'); table.string('name', 100).notNullable(); table.string('current_location', 20).notNullable(); // Coordinates table.string('destination', 20).nullable(); // If moving table.string('fleet_status', 20).defaultTo('idle') .checkIn(['idle', 'moving', 'in_combat', 'constructing', 'repairing']); table.timestamp('movement_started').nullable(); table.timestamp('arrival_time').nullable(); table.timestamp('last_updated').defaultTo(knex.fn.now()); table.timestamp('created_at').defaultTo(knex.fn.now()); table.index(['player_id']); table.index(['current_location']); table.index(['fleet_status']); table.index(['arrival_time']); }) // Create ship_designs table .createTable('ship_designs', (table) => { table.increments('id').primary(); table.integer('player_id').nullable().references('players.id').onDelete('CASCADE'); // NULL for public designs table.string('name', 100).notNullable(); table.string('ship_class', 50).notNullable(); // 'fighter', 'corvette', 'destroyer', 'cruiser', 'battleship' table.string('hull_type', 50).notNullable(); table.jsonb('components').notNullable(); // Weapon, shield, engine configurations table.jsonb('stats').notNullable(); // Calculated stats: hp, attack, defense, speed, etc. table.jsonb('cost').notNullable(); // Resource cost to build table.integer('build_time').notNullable(); // In minutes table.boolean('is_public').defaultTo(false); // Available to all players table.boolean('is_active').defaultTo(true); table.timestamp('created_at').defaultTo(knex.fn.now()); table.timestamp('updated_at').defaultTo(knex.fn.now()); table.index(['player_id']); table.index(['ship_class']); table.index(['is_public']); table.index(['is_active']); }) // Create fleet_ships table .createTable('fleet_ships', (table) => { table.increments('id').primary(); table.integer('fleet_id').notNullable().references('fleets.id').onDelete('CASCADE'); table.integer('ship_design_id').notNullable().references('ship_designs.id').onDelete('CASCADE'); table.integer('quantity').notNullable().defaultTo(1); table.decimal('health_percentage', 5, 2).defaultTo(100.00); table.integer('experience').defaultTo(0); table.timestamp('created_at').defaultTo(knex.fn.now()); table.index(['fleet_id']); table.index(['ship_design_id']); }); }; exports.down = function(knex) { return knex.schema .dropTableIfExists('fleet_ships') .dropTableIfExists('ship_designs') .dropTableIfExists('fleets'); };