Skip to content

Commit 8daac34

Browse files
committed
Add Migration update
1 parent ab776b9 commit 8daac34

10 files changed

+132
-31
lines changed

database/migrations/0001_01_01_000002_create_connected_accounts_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function up(): void
2626
$table->dateTime('expires_at')->nullable(); // OAuth2
2727
$table->timestamps();
2828

29-
$table->index(['user_id', 'id']);
30-
$table->index(['provider', 'provider_id']);
29+
$table->index(['user_id', 'id'], 'connected_accounts_user_id_id_idx');
30+
$table->index(['provider', 'provider_id'], 'connected_accounts_provider_provider_id_idx');
3131
});
3232
}
3333

database/migrations/2024_01_15_000001_create_subscriptions_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public function up(): void
2020
$table->timestamp('ends_at')->nullable();
2121
$table->timestamps();
2222

23-
$table->index(['user_id', 'stripe_status']);
23+
$table->index(['user_id', 'stripe_status'], 'subscriptions_user_id_status_idx');
2424
});
2525
}
2626

2727
public function down(): void
2828
{
2929
Schema::dropIfExists('subscriptions');
3030
}
31-
};
31+
};

database/migrations/2024_01_15_000005_create_smart_matches_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public function up(): void
2121
$table->timestamp('reviewed_at')->nullable();
2222
$table->timestamps();
2323

24-
$table->index(['user_id', 'status']);
25-
$table->index(['person_id', 'confidence_score']);
24+
$table->index(['user_id', 'status'], 'smart_matches_user_id_status_idx');
25+
$table->index(['person_id', 'confidence_score'], 'smart_matches_person_id_confidence_idx');
2626
});
2727
}
2828

2929
public function down(): void
3030
{
3131
Schema::dropIfExists('smart_matches');
3232
}
33-
};
33+
};

database/migrations/2024_01_16_000001_create_checklist_templates_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public function up(): void
2525
$table->timestamps();
2626
$table->softDeletes();
2727

28-
$table->index(['category', 'is_public']);
29-
$table->index(['is_default', 'is_public']);
28+
$table->index(['category', 'is_public'], 'checklist_templates_category_public_idx');
29+
$table->index(['is_default', 'is_public'], 'checklist_templates_default_public_idx');
3030
});
3131
}
3232

@@ -37,4 +37,4 @@ public function down(): void
3737
{
3838
Schema::dropIfExists('checklist_templates');
3939
}
40-
};
40+
};

database/migrations/2024_01_16_000002_create_checklist_template_items_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function up(): void
2424
$table->json('tips')->nullable()->comment('Helpful tips and notes');
2525
$table->timestamps();
2626

27-
$table->index(['checklist_template_id', 'order']);
27+
$table->index(['checklist_template_id', 'order'], 'checklist_template_items_template_id_order_idx');
2828
$table->index(['category']);
2929
});
3030
}
@@ -36,4 +36,4 @@ public function down(): void
3636
{
3737
Schema::dropIfExists('checklist_template_items');
3838
}
39-
};
39+
};

database/migrations/2024_01_16_000003_create_user_checklists_table.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function up(): void
2828
$table->timestamps();
2929
$table->softDeletes();
3030

31-
$table->index(['user_id', 'status']);
32-
$table->index(['subject_type', 'subject_id']);
33-
$table->index(['priority', 'due_date']);
34-
$table->index(['status', 'due_date']);
31+
$table->index(['user_id', 'status'], 'user_checklists_user_status_idx');
32+
$table->index(['subject_type', 'subject_id'], 'user_checklists_subject_type_id_idx');
33+
$table->index(['priority', 'due_date'], 'user_checklists_priority_due_date_idx');
34+
$table->index(['status', 'due_date'], 'user_checklists_status_due_date_idx');
3535
});
3636
}
3737

@@ -42,4 +42,4 @@ public function down(): void
4242
{
4343
Schema::dropIfExists('user_checklists');
4444
}
45-
};
45+
};

database/migrations/2024_01_16_000004_create_user_checklist_items_table.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function up(): void
2727
$table->json('tips')->nullable()->comment('Helpful tips and notes');
2828
$table->timestamps();
2929

30-
$table->index(['user_checklist_id', 'order']);
31-
$table->index(['user_checklist_id', 'is_completed']);
32-
$table->index(['is_completed', 'completed_at']);
30+
$table->index(['user_checklist_id', 'order'], 'user_checklist_items_checklist_order_idx');
31+
$table->index(['user_checklist_id', 'is_completed'], 'user_checklist_items_checklist_completed_idx');
32+
$table->index(['is_completed', 'completed_at'], 'user_checklist_items_completed_date_idx');
3333
});
3434
}
3535

@@ -40,4 +40,4 @@ public function down(): void
4040
{
4141
Schema::dropIfExists('user_checklist_items');
4242
}
43-
};
43+
};

database/migrations/2024_01_17_000001_create_virtual_events_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function up(): void
3535
$table->timestamps();
3636
$table->softDeletes();
3737

38-
$table->index(['team_id', 'status']);
39-
$table->index(['start_time', 'end_time']);
38+
$table->index(['team_id', 'status'], 'virtual_events_team_status_idx');
39+
$table->index(['start_time', 'end_time'], 'virtual_events_start_end_idx');
4040
});
4141
}
4242

@@ -47,4 +47,4 @@ public function down(): void
4747
{
4848
Schema::dropIfExists('virtual_events');
4949
}
50-
};
50+
};

database/migrations/2026_02_28_120000_fix_social_family_connections_index.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ public function up(): void
1313
{
1414
if (Schema::hasTable('social_family_connections')) {
1515
Schema::table('social_family_connections', function (Blueprint $table) {
16-
// drop the short index if it exists; this avoids ever mentioning the
17-
// long, auto-generated name which MySQL refuses to parse.
18-
// We use the explicit name so Laravel doesn't build the default one.
19-
$table->dropIndex('sfc_account_social_id_idx');
20-
21-
// now ensure the properly named, shorter index is present. If it
22-
// already exists the builder will ignore the second creation.
16+
// the previously-added index already has the correct short name.
17+
// dropping it can fail if MySQL is using it for the foreign-key
18+
// on connected_account_id, so we simply avoid removing it here.
19+
// Laravel will ignore attempts to recreate an existing index, so
20+
// the call below is safe in all cases.
2321
$table->index(
2422
['connected_account_id', 'matched_social_id'],
2523
'sfc_account_social_id_idx'
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Support\Facades\DB;
7+
8+
return new class extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*/
13+
public function up(): void
14+
{
15+
$definitions = [
16+
'connected_accounts' => [
17+
[['user_id', 'id'], 'connected_accounts_user_id_id_idx'],
18+
[['provider', 'provider_id'], 'connected_accounts_provider_provider_id_idx'],
19+
],
20+
'subscriptions' => [
21+
[['user_id', 'stripe_status'], 'subscriptions_user_id_status_idx'],
22+
],
23+
'smart_matches' => [
24+
[['user_id', 'status'], 'smart_matches_user_id_status_idx'],
25+
[['person_id', 'confidence_score'], 'smart_matches_person_id_confidence_idx'],
26+
],
27+
'checklist_template_items' => [
28+
[['checklist_template_id', 'order'], 'checklist_template_items_template_id_order_idx'],
29+
],
30+
'checklist_templates' => [
31+
[['category', 'is_public'], 'checklist_templates_category_public_idx'],
32+
[['is_default', 'is_public'], 'checklist_templates_default_public_idx'],
33+
],
34+
'user_checklists' => [
35+
[['user_id', 'status'], 'user_checklists_user_status_idx'],
36+
[['subject_type', 'subject_id'], 'user_checklists_subject_type_id_idx'],
37+
[['priority', 'due_date'], 'user_checklists_priority_due_date_idx'],
38+
[['status', 'due_date'], 'user_checklists_status_due_date_idx'],
39+
],
40+
'user_checklist_items' => [
41+
[['user_checklist_id', 'order'], 'user_checklist_items_checklist_order_idx'],
42+
[['user_checklist_id', 'is_completed'], 'user_checklist_items_checklist_completed_idx'],
43+
[['is_completed', 'completed_at'], 'user_checklist_items_completed_date_idx'],
44+
],
45+
'virtual_events' => [
46+
[['team_id', 'status'], 'virtual_events_team_status_idx'],
47+
[['start_time', 'end_time'], 'virtual_events_start_end_idx'],
48+
],
49+
];
50+
51+
foreach ($definitions as $tableName => $indexes) {
52+
if (!Schema::hasTable($tableName)) {
53+
continue;
54+
}
55+
Schema::table($tableName, function (Blueprint $table) use ($indexes, $tableName) {
56+
foreach ($indexes as [$columns, $name]) {
57+
// drop any auto-generated long form if present
58+
$longName = $tableName . '_' . implode('_', $columns) . '_index';
59+
DB::statement("DROP INDEX IF EXISTS `$longName` ON `$tableName`");
60+
61+
// create the index with the explicit name; if it already
62+
// exists this will quietly do nothing
63+
$table->index($columns, $name);
64+
}
65+
});
66+
}
67+
}
68+
69+
/**
70+
* Reverse the migrations.
71+
*/
72+
public function down(): void
73+
{
74+
foreach ([
75+
'connected_accounts_user_id_id_idx',
76+
'connected_accounts_provider_provider_id_idx',
77+
'subscriptions_user_id_status_idx',
78+
'smart_matches_user_id_status_idx',
79+
'smart_matches_person_id_confidence_idx',
80+
'checklist_template_items_template_id_order_idx',
81+
'checklist_templates_category_public_idx',
82+
'checklist_templates_default_public_idx',
83+
'user_checklists_user_status_idx',
84+
'user_checklists_subject_type_id_idx',
85+
'user_checklists_priority_due_date_idx',
86+
'user_checklists_status_due_date_idx',
87+
'user_checklist_items_checklist_order_idx',
88+
'user_checklist_items_checklist_completed_idx',
89+
'user_checklist_items_completed_date_idx',
90+
'virtual_events_team_status_idx',
91+
'virtual_events_start_end_idx',
92+
] as $idx) {
93+
// can't easily know which table the index belongs to, so run a
94+
// blind ALTER. If it fails because the index doesn't exist we'll
95+
// ignore it (the statement is wrapped in try/catch).
96+
// We prefer DB::statement so we can use IF EXISTS safely.
97+
// Extract table name from index naming convention.
98+
$parts = explode('_', $idx);
99+
$tableName = $parts[0];
100+
DB::statement("DROP INDEX IF EXISTS `$idx` ON `$tableName`");
101+
}
102+
}
103+
};

0 commit comments

Comments
 (0)