Skip to content

Commit d07d2be

Browse files
author
nejc
committed
refactor: consolidate all migrations into single optimized migration file
- Replace 5 separate migration files with one consolidated migration - Maintain all table structures, indexes, and foreign key constraints - Improve package installation performance and maintainability - Ensure proper table creation order for foreign key dependencies - Include safe rollback functionality in reverse order
1 parent d9a11bc commit d07d2be

6 files changed

+100
-187
lines changed

database/migrations/2024_01_01_000000_create_platform_versions_table.php

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
// Create platform_versions table
15+
Schema::create('platform_versions', function (Blueprint $table) {
16+
$table->id();
17+
$table->string('version')->unique();
18+
$table->string('title');
19+
$table->text('description')->nullable();
20+
$table->boolean('is_active')->default(true);
21+
$table->timestamp('released_at')->nullable();
22+
$table->json('metadata')->nullable();
23+
$table->timestamps();
24+
$table->softDeletes();
25+
26+
// Indexes for better performance
27+
$table->index(['version']);
28+
$table->index(['is_active']);
29+
$table->index(['released_at']);
30+
$table->index(['created_at']);
31+
});
32+
33+
// Create whats_new table (without title column as per the simplification)
34+
Schema::create('whats_new', function (Blueprint $table) {
35+
$table->id();
36+
$table->foreignId('platform_version_id')->constrained()->onDelete('cascade');
37+
$table->text('content');
38+
$table->enum('type', ['feature', 'improvement', 'bugfix', 'security', 'deprecation'])->default('feature');
39+
$table->boolean('is_active')->default(true);
40+
$table->integer('sort_order')->default(0);
41+
$table->json('metadata')->nullable();
42+
$table->timestamps();
43+
$table->softDeletes();
44+
45+
// Indexes for better performance
46+
$table->index(['platform_version_id']);
47+
$table->index(['type']);
48+
$table->index(['is_active']);
49+
$table->index(['sort_order']);
50+
$table->index(['created_at']);
51+
});
52+
53+
// Create user_versions table
54+
Schema::create('user_versions', function (Blueprint $table) {
55+
$table->id();
56+
$table->foreignId('user_id')->constrained()->onDelete('cascade');
57+
$table->string('version')->default('1.0.0');
58+
$table->string('last_seen_version')->nullable();
59+
$table->timestamp('last_seen_at')->nullable();
60+
$table->json('metadata')->nullable();
61+
$table->timestamps();
62+
63+
// Indexes for better performance
64+
$table->index(['user_id']);
65+
$table->index(['version']);
66+
$table->index(['last_seen_version']);
67+
$table->index(['updated_at']);
68+
69+
// Unique constraint to ensure one record per user
70+
$table->unique(['user_id']);
71+
});
72+
73+
// Add version column to users table
74+
Schema::table('users', function (Blueprint $table) {
75+
if (!Schema::hasColumn('users', 'version')) {
76+
$table->string('version')->default('1.0.0')->after('is_read_news');
77+
$table->index(['version']);
78+
}
79+
});
80+
}
81+
82+
/**
83+
* Reverse the migrations.
84+
*/
85+
public function down(): void
86+
{
87+
// Remove version column from users table
88+
Schema::table('users', function (Blueprint $table) {
89+
if (Schema::hasColumn('users', 'version')) {
90+
$table->dropIndex(['version']);
91+
$table->dropColumn('version');
92+
}
93+
});
94+
95+
// Drop tables in reverse order (respecting foreign key constraints)
96+
Schema::dropIfExists('user_versions');
97+
Schema::dropIfExists('whats_new');
98+
Schema::dropIfExists('platform_versions');
99+
}
100+
};

database/migrations/2024_01_01_000001_create_whats_new_table.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

database/migrations/2024_01_01_000002_create_user_versions_table.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

database/migrations/2024_01_01_000003_add_version_to_users_table.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

database/migrations/2024_01_01_000004_simplify_whats_new_table.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)