Fix migrations for SQLite: add hasColumn check, replace SHOW INDEX with Doctrine schema manager

This commit is contained in:
root
2026-06-21 13:49:04 -04:00
parent 1d246fff93
commit 588b40d0fa
2 changed files with 7 additions and 3 deletions
@@ -11,6 +11,9 @@ return new class extends Migration
*/
public function up(): void
{
if (Schema::hasColumn('student_class', 'semester')) {
return;
}
Schema::table('student_class', function (Blueprint $table) {
$table->string('semester', 255)->default('')->after('is_event_only');
});
@@ -18,9 +18,10 @@ return new class extends Migration
}
});
// Add index if it doesn't exist
$indexExists = DB::select("SHOW INDEX FROM purchase_order_items WHERE Key_name = 'po_items_inventory_item_idx'");
if (empty($indexExists)) {
// Add index if it doesn't exist (SQLite-compatible check)
$schema = DB::connection()->getDoctrineSchemaManager();
$indexes = $schema->listTableIndexes('purchase_order_items');
if (! isset($indexes['po_items_inventory_item_idx'])) {
Schema::table('purchase_order_items', function (Blueprint $table) {
$table->index('inventory_item_id', 'po_items_inventory_item_idx');
});