Browse Source

Fix migrations

Daniel Supernault 1 year ago
parent
commit
4d1180b1c1

+ 0 - 7
database/migrations/2018_08_12_042648_update_status_table_change_caption_to_text.php

@@ -5,13 +5,6 @@ use Illuminate\Support\Facades\Schema;
 
 class UpdateStatusTableChangeCaptionToText extends Migration
 {
-    public function __construct()
-    {
-        DB::getDoctrineSchemaManager()
-            ->getDatabasePlatform()
-            ->registerDoctrineTypeMapping('enum', 'string');
-    }
-
     /**
      * Run the migrations.
      *

+ 0 - 5
database/migrations/2019_03_12_043935_add_snowflakeids_to_users_table.php

@@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
 
 class AddSnowflakeidsToUsersTable extends Migration
 {
-    public function __construct()
-    {
-        DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
-    }
-
     /**
      * Run the migrations.
      *

+ 0 - 5
database/migrations/2019_04_16_184644_add_layout_to_profiles_table.php

@@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
 
 class AddLayoutToProfilesTable extends Migration
 {
-    public function __construct()
-    {
-        DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
-    }
-
     /**
      * Run the migrations.
      *

+ 0 - 5
database/migrations/2019_04_25_200411_add_snowflake_ids_to_collections_table.php

@@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
 
 class AddSnowflakeIdsToCollectionsTable extends Migration
 {
-    public function __construct()
-    {
-        DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
-    }
-
     /**
      * Run the migrations.
      *

+ 0 - 5
database/migrations/2019_08_12_074612_add_unique_to_statuses_table.php

@@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
 
 class AddUniqueToStatusesTable extends Migration
 {
-    public function __construct()
-    {
-        DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
-    }
-
     /**
      * Run the migrations.
      *

+ 0 - 5
database/migrations/2019_09_09_032757_add_object_id_to_statuses_table.php

@@ -6,11 +6,6 @@ use Illuminate\Database\Migrations\Migration;
 
 class AddObjectIdToStatusesTable extends Migration
 {
-    public function __construct()
-    {
-        DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
-    }
-
     /**
      * Run the migrations.
      *

+ 0 - 4
database/migrations/2019_12_25_042317_update_stories_table.php

@@ -6,10 +6,6 @@ use Illuminate\Support\Facades\Schema;
 
 class UpdateStoriesTable extends Migration
 {
-    public function __construct()
-    {
-        DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
-    }
     /**
      * Run the migrations.
      *

+ 5 - 5
database/migrations/2021_07_23_062326_add_compose_settings_to_user_settings_table.php

@@ -41,15 +41,15 @@ class AddComposeSettingsToUserSettingsTable extends Migration
         Schema::table('media', function (Blueprint $table) {
             $table->string('caption')->change();
 
-            $schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound  = $schemaManager->listTableIndexes('media');
-            if (array_key_exists('media_profile_id_index', $indexesFound)) {
+            $indexes = Schema::getIndexes('media');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('media_profile_id_index', $indexesFound)) {
                 $table->dropIndex('media_profile_id_index');
             }
-            if (array_key_exists('media_mime_index', $indexesFound)) {
+            if (in_array('media_mime_index', $indexesFound)) {
                 $table->dropIndex('media_mime_index');
             }
-            if (array_key_exists('media_license_index', $indexesFound)) {
+            if (in_array('media_license_index', $indexesFound)) {
                 $table->dropIndex('media_license_index');
             }
         });

+ 10 - 12
database/migrations/2021_08_23_062246_update_stories_table_fix_expires_at_column.php

@@ -14,12 +14,11 @@ class UpdateStoriesTableFixExpiresAtColumn extends Migration
 	public function up()
 	{
 		Schema::table('stories', function (Blueprint $table) {
-			$sm = Schema::getConnection()->getDoctrineSchemaManager();
-			$doctrineTable = $sm->listTableDetails('stories');
-
-			if($doctrineTable->hasIndex('stories_expires_at_index')) {
-				$table->dropIndex('stories_expires_at_index');
-			}
+            $indexes = Schema::getIndexes('stories');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('stories_expires_at_index', $indexesFound)) {
+                $table->dropIndex('stories_expires_at_index');
+            }
 			$table->timestamp('expires_at')->default(null)->index()->nullable()->change();
 			$table->boolean('can_reply')->default(true);
 			$table->boolean('can_react')->default(true);
@@ -37,12 +36,11 @@ class UpdateStoriesTableFixExpiresAtColumn extends Migration
 	public function down()
 	{
 		Schema::table('stories', function (Blueprint $table) {
-			$sm = Schema::getConnection()->getDoctrineSchemaManager();
-			$doctrineTable = $sm->listTableDetails('stories');
-
-			if($doctrineTable->hasIndex('stories_expires_at_index')) {
-				$table->dropIndex('stories_expires_at_index');
-			}
+			$indexes = Schema::getIndexes('stories');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('stories_expires_at_index', $indexesFound)) {
+                $table->dropIndex('stories_expires_at_index');
+            }
 			$table->timestamp('expires_at')->default(null)->index()->nullable()->change();
 			$table->dropColumn('can_reply');
 			$table->dropColumn('can_react');

+ 3 - 2
database/migrations/2022_10_07_055133_remove_old_compound_index_from_statuses_table.php

@@ -14,8 +14,9 @@ class RemoveOldCompoundIndexFromStatusesTable extends Migration
     public function up()
     {
         Schema::table('statuses', function (Blueprint $table) {
-            $sc = Schema::getConnection()->getDoctrineSchemaManager();
-            if(array_key_exists('statuses_in_reply_to_id_reblog_of_id_index', $sc->listTableIndexes('statuses'))) {
+            $indexes = Schema::getIndexes('statuses');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('statuses_in_reply_to_id_reblog_of_id_index', $indexesFound)) {
                 $table->dropIndex('statuses_in_reply_to_id_reblog_of_id_index');
             }
         });

+ 3 - 3
database/migrations/2022_11_30_123940_update_avatars_table_remove_cdn_url_unique_constraint.php

@@ -14,9 +14,9 @@ return new class extends Migration
     public function up()
     {
         Schema::table('avatars', function (Blueprint $table) {
-            $sm = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound = $sm->listTableIndexes('avatars');
-            if(array_key_exists("avatars_cdn_url_unique", $indexesFound)) {
+            $indexes = Schema::getIndexes('avatars');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('avatars_cdn_url_unique', $indexesFound)) {
                 $table->dropUnique('avatars_cdn_url_unique');
             }
         });

+ 6 - 6
database/migrations/2024_01_09_052419_create_parental_controls_table.php

@@ -25,9 +25,9 @@ return new class extends Migration
         });
 
         Schema::table('user_roles', function (Blueprint $table) {
-            $schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound  = $schemaManager->listTableIndexes('user_roles');
-            if (array_key_exists('user_roles_profile_id_unique', $indexesFound)) {
+            $indexes = Schema::getIndexes('user_roles');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('user_roles_profile_id_unique', $indexesFound)) {
                 $table->dropUnique('user_roles_profile_id_unique');
             }
             $table->unsignedBigInteger('profile_id')->unique()->nullable()->index()->change();
@@ -42,9 +42,9 @@ return new class extends Migration
         Schema::dropIfExists('parental_controls');
 
         Schema::table('user_roles', function (Blueprint $table) {
-            $schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound  = $schemaManager->listTableIndexes('user_roles');
-            if (array_key_exists('user_roles_profile_id_unique', $indexesFound)) {
+            $indexes = Schema::getIndexes('user_roles');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('user_roles_profile_id_unique', $indexesFound)) {
                 $table->dropUnique('user_roles_profile_id_unique');
             }
             $table->unsignedBigInteger('profile_id')->unique()->index()->change();

+ 6 - 6
database/migrations/2024_05_31_090555_update_instances_table_add_index_to_nodeinfo_last_fetched_at.php

@@ -12,9 +12,9 @@ return new class extends Migration
     public function up(): void
     {
         Schema::table('instances', function (Blueprint $table) {
-            $schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound = $schemaManager->listTableIndexes('instances');
-            if (! array_key_exists('instances_nodeinfo_last_fetched_index', $indexesFound)) {
+            $indexes = Schema::getIndexes('instances');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (!in_array('instances_nodeinfo_last_fetched_index', $indexesFound)) {
                 $table->index('nodeinfo_last_fetched');
             }
         });
@@ -26,9 +26,9 @@ return new class extends Migration
     public function down(): void
     {
         Schema::table('instances', function (Blueprint $table) {
-            $schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound = $schemaManager->listTableIndexes('instances');
-            if (array_key_exists('instances_nodeinfo_last_fetched_index', $indexesFound)) {
+            $indexes = Schema::getIndexes('instances');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('instances_nodeinfo_last_fetched_index', $indexesFound)) {
                 $table->dropIndex('instances_nodeinfo_last_fetched_index');
             }
         });

+ 6 - 6
database/migrations/2024_06_03_232204_add_url_index_to_statuses_table.php

@@ -12,9 +12,9 @@ return new class extends Migration
     public function up(): void
     {
         Schema::table('statuses', function (Blueprint $table) {
-            $schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound = $schemaManager->listTableIndexes('statuses');
-            if (! array_key_exists('statuses_url_index', $indexesFound)) {
+            $indexes = Schema::getIndexes('statuses');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (!in_array('statuses_url_index', $indexesFound)) {
                 $table->index('url');
             }
         });
@@ -26,9 +26,9 @@ return new class extends Migration
     public function down(): void
     {
         Schema::table('statuses', function (Blueprint $table) {
-            $schemaManager = Schema::getConnection()->getDoctrineSchemaManager();
-            $indexesFound = $schemaManager->listTableIndexes('statuses');
-            if (array_key_exists('statuses_url_index', $indexesFound)) {
+            $indexes = Schema::getIndexes('statuses');
+            $indexesFound = collect($indexes)->map(function($i) { return $i['name']; })->toArray();
+            if (in_array('statuses_url_index', $indexesFound)) {
                 $table->dropIndex('statuses_url_index');
             }
         });