fix: add json translation columns migration, re-add /vendor to .gitignore
This commit is contained in:
parent
db0cf119ab
commit
e3e5033fec
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
|||||||
/public/hot
|
/public/hot
|
||||||
/public/storage
|
/public/storage
|
||||||
/storage/*.key
|
/storage/*.key
|
||||||
|
/vendor
|
||||||
.env
|
.env
|
||||||
.env.backup
|
.env.backup
|
||||||
.env.production
|
.env.production
|
||||||
|
|||||||
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
// Add JSON columns for spatie/laravel-translatable on website_about_me
|
||||||
|
Schema::table('website_about_me', function (Blueprint $table) {
|
||||||
|
if (!Schema::hasColumn('website_about_me', 'title')) {
|
||||||
|
$table->json('title')->nullable()->after('image');
|
||||||
|
}
|
||||||
|
if (!Schema::hasColumn('website_about_me', 'description')) {
|
||||||
|
$table->json('description')->nullable()->after('title');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Migrate data from translations table to JSON columns
|
||||||
|
DB::statement('
|
||||||
|
UPDATE website_about_me a
|
||||||
|
SET a.title = (
|
||||||
|
SELECT JSON_OBJECTAGG(locale, title)
|
||||||
|
FROM website_about_me_translations t
|
||||||
|
WHERE t.about_me_id = a.id
|
||||||
|
),
|
||||||
|
a.description = (
|
||||||
|
SELECT JSON_OBJECTAGG(locale, description)
|
||||||
|
FROM website_about_me_translations t
|
||||||
|
WHERE t.about_me_id = a.id
|
||||||
|
)
|
||||||
|
');
|
||||||
|
|
||||||
|
// Add JSON columns for spatie/laravel-translatable on website_skills
|
||||||
|
Schema::table('website_skills', function (Blueprint $table) {
|
||||||
|
if (!Schema::hasColumn('website_skills', 'title')) {
|
||||||
|
$table->json('title')->nullable()->after('image');
|
||||||
|
}
|
||||||
|
if (!Schema::hasColumn('website_skills', 'description')) {
|
||||||
|
$table->json('description')->nullable()->after('title');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Migrate data from skill translations table to JSON columns
|
||||||
|
DB::statement('
|
||||||
|
UPDATE website_skills s
|
||||||
|
SET s.title = (
|
||||||
|
SELECT JSON_OBJECTAGG(locale, title)
|
||||||
|
FROM website_skill_translations t
|
||||||
|
WHERE t.skill_id = s.id
|
||||||
|
),
|
||||||
|
s.description = (
|
||||||
|
SELECT JSON_OBJECTAGG(locale, description)
|
||||||
|
FROM website_skill_translations t
|
||||||
|
WHERE t.skill_id = s.id
|
||||||
|
)
|
||||||
|
');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('website_about_me', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['title', 'description']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('website_skills', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['title', 'description']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user