fixed the migrations

This commit is contained in:
Doar Mihai
2026-03-21 11:59:04 +02:00
parent 49b1d3581a
commit bfc13c022d
8 changed files with 78 additions and 9 deletions
@@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
@@ -22,8 +23,10 @@ return new class extends Migration
$table->timestamps();
$table->index(['website_id', 'viewed_at']);
$table->index('path');
});
// Index only the first 255 characters of path to avoid key length issues
DB::statement('ALTER TABLE page_views ADD INDEX page_views_path_index (path(255))');
}
public function down(): void
@@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
@@ -19,9 +20,11 @@ return new class extends Migration
$table->unsignedInteger('bounces')->default(0);
$table->timestamps();
$table->unique(['website_id', 'date', 'path']);
$table->index(['website_id', 'date']);
});
// Create unique constraint with prefix length on path to avoid key length issues
DB::statement('ALTER TABLE page_daily_aggregates ADD UNIQUE page_daily_aggregates_website_id_date_path_unique (website_id, date, path(255))');
}
public function down(): void
@@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
@@ -16,10 +17,12 @@ return new class extends Migration
Schema::table('analytics_sessions', function (Blueprint $table) {
$table->index('visitor_id', 'sess_visitor_id_idx');
$table->index(['website_id', 'is_bounce', 'started_at'], 'sess_bounce_lookup_idx');
$table->index(['website_id', 'entry_page'], 'sess_entry_page_idx');
$table->index(['website_id', 'exit_page'], 'sess_exit_page_idx');
});
// Add indexes with prefix length on TEXT columns to avoid key length issues
DB::statement('ALTER TABLE analytics_sessions ADD INDEX sess_entry_page_idx (website_id, entry_page(255))');
DB::statement('ALTER TABLE analytics_sessions ADD INDEX sess_exit_page_idx (website_id, exit_page(255))');
Schema::table('events', function (Blueprint $table) {
$table->index('visitor_id', 'ev_visitor_id_idx');
});
@@ -39,10 +42,11 @@ return new class extends Migration
Schema::table('analytics_sessions', function (Blueprint $table) {
$table->dropIndex('sess_visitor_id_idx');
$table->dropIndex('sess_bounce_lookup_idx');
$table->dropIndex('sess_entry_page_idx');
$table->dropIndex('sess_exit_page_idx');
});
DB::statement('ALTER TABLE analytics_sessions DROP INDEX sess_entry_page_idx');
DB::statement('ALTER TABLE analytics_sessions DROP INDEX sess_exit_page_idx');
Schema::table('events', function (Blueprint $table) {
$table->dropIndex('ev_visitor_id_idx');
});
+1
View File
@@ -20,6 +20,7 @@ class DatabaseSeeder extends Seeder
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
'password' => bcrypt('password'),
]);
}
}