diff --git a/database/migrations/2026_09_14_000002_update_wikis_primary_key_column_type.php b/database/migrations/2026_09_14_000002_update_wikis_primary_key_column_type.php new file mode 100644 index 000000000..783d92b46 --- /dev/null +++ b/database/migrations/2026_09_14_000002_update_wikis_primary_key_column_type.php @@ -0,0 +1,109 @@ +dropForeign(['wiki_id']); + }); + } + + /** + * UPDATE PRIMARY KEY COLUMN TYPE + */ + Schema::table('wikis', function (Blueprint $table) { + $table->id()->change(); + }); + + /** + * UPDATE FOREIGN KEY COLUMN TYPE AND RECREATE DROPPED CONSTRAINTS + */ + foreach (self::TABLES_WITH_FOREIGN_KEY_CONSTRAINTS as $tableName) { + Schema::table($tableName, function (Blueprint $table) { + $table->foreignId('wiki_id') + ->change() + ->constrained() + ->restrictOnUpdate() + ->restrictOnDelete(); + }); + } + } + + /** + * Reverse the migrations. + */ + public function down(): void { + /** + * DROP EXISTING FOREIGN KEY CONSTRAINTS + */ + foreach (self::TABLES_WITH_FOREIGN_KEY_CONSTRAINTS as $tableName) { + Schema::table($tableName, function (Blueprint $table) { + $table->dropForeign(['wiki_id']); + }); + } + + /** + * REVERSE PRIMARY KEY COLUMN TYPE CHANGE + */ + Schema::table('wikis', function (Blueprint $table) { + $table->increments('id')->change(); + }); + + /** + * REVERSE FOREIGN KEY COLUMN TYPE CHANGE AND RECREATE DROPPED CONSTRAINTS + * + * Can't use a foreach loop as not all `wiki_id` columns were created the same + */ + Schema::table('knowledge_equity_responses', function (Blueprint $table) { + $table->unsignedInteger('wiki_id')->change(); + $table->foreign('wiki_id')->references('id')->on('wikis') + ->restrictOnDelete() + ->restrictOnUpdate(); + }); + + Schema::table('wiki_entity_imports', function (Blueprint $table) { + $table->unsignedInteger('wiki_id')->change(); + $table->foreign('wiki_id')->references('id')->on('wikis'); + }); + + Schema::table('wiki_lifecycle_events', function (Blueprint $table) { + $table->unsignedInteger('wiki_id')->change(); + $table->foreign('wiki_id')->references('id')->on('wikis'); + }); + + Schema::table('wiki_notification_sent_records', function (Blueprint $table) { + $table->unsignedInteger('wiki_id')->change(); + }); + + Schema::table('wiki_profiles', function (Blueprint $table) { + $table->unsignedInteger('wiki_id')->change(); + $table->foreign('wiki_id')->references('id')->on('wikis'); + }); + + Schema::table('wiki_site_stats', function (Blueprint $table) { + $table->unsignedInteger('wiki_id')->change(); + $table->foreign('wiki_id')->references('id')->on('wikis'); + }); + } +};