Fix migrations

This commit is contained in:
Daniel Supernault 2024-07-01 02:39:42 -06:00
parent 88fcb8f36b
commit 4d1180b1c1
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
14 changed files with 39 additions and 76 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -14,8 +14,9 @@ class RemoveOldCompoundIndexFromStatusesTable extends Migration
public function up() public function up()
{ {
Schema::table('statuses', function (Blueprint $table) { Schema::table('statuses', function (Blueprint $table) {
$sc = Schema::getConnection()->getDoctrineSchemaManager(); $indexes = Schema::getIndexes('statuses');
if(array_key_exists('statuses_in_reply_to_id_reblog_of_id_index', $sc->listTableIndexes('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'); $table->dropIndex('statuses_in_reply_to_id_reblog_of_id_index');
} }
}); });

View file

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

View file

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

View file

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

View file

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