From 0960af03732fa98f415b0b4c56e7425cab4e9c15 Mon Sep 17 00:00:00 2001 From: Nicolas Hedger <649677+nhedger@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:28:04 +0100 Subject: [PATCH] fix: migrations not passing on pgsql (#242) * fix: migration not passing on pgsql * pin postgres version --- .github/workflows/laravel.yml | 2 +- .../2021_05_19_140326_create_forms_table.php | 11 ++++++-- ...4_234028_create_form_submissions_table.php | 11 ++++++-- .../2022_05_10_144947_form_statistic.php | 11 ++++++-- ...133641_add_removed_properties_to_forms.php | 11 ++++++-- ...22_09_22_092205_create_templates_table.php | 11 ++++++-- ...9_26_084721_add_questions_to_templates.php | 11 ++++++-- ...023_07_20_073728_add_seo_meta_to_forms.php | 11 ++++++-- ...710_add_notification_settings_to_forms.php | 11 ++++++-- ...3_09_01_052507_add_fields_to_templates.php | 28 ++++++++++++++++--- 10 files changed, 97 insertions(+), 21 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 7635c20..6d24a2b 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -12,7 +12,7 @@ jobs: services: postgres: # Docker Hub image - image: postgres + image: postgres:14 # Provide the password for postgres env: POSTGRES_PASSWORD: postgres diff --git a/database/migrations/2021_05_19_140326_create_forms_table.php b/database/migrations/2021_05_19_140326_create_forms_table.php index a4b6af4..7aa63a9 100644 --- a/database/migrations/2021_05_19_140326_create_forms_table.php +++ b/database/migrations/2021_05_19_140326_create_forms_table.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; class CreateFormsTable extends Migration @@ -14,7 +15,9 @@ class CreateFormsTable extends Migration */ public function up() { - Schema::create('forms', function (Blueprint $table) { + $driver = DB::getDriverName(); + + Schema::create('forms', function (Blueprint $table) use ($driver) { $table->id(); $table->foreignIdFor(\App\Models\Workspace::class,'workspace_id'); $table->string('title'); @@ -52,7 +55,11 @@ class CreateFormsTable extends Migration $table->boolean('can_be_indexed')->default(true); $table->string('password')->nullable()->default(null); $table->string('notification_sender')->default("OpenForm"); - $table->jsonb('tags')->default(new Expression('(JSON_ARRAY())')); + if ($driver === 'mysql') { + $table->jsonb('tags')->default(new Expression('(JSON_ARRAY())')); + } else { + $table->jsonb('tags')->default('[]'); + } }); } diff --git a/database/migrations/2021_05_24_234028_create_form_submissions_table.php b/database/migrations/2021_05_24_234028_create_form_submissions_table.php index b292103..b7e48af 100644 --- a/database/migrations/2021_05_24_234028_create_form_submissions_table.php +++ b/database/migrations/2021_05_24_234028_create_form_submissions_table.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; class CreateFormSubmissionsTable extends Migration @@ -14,10 +15,16 @@ class CreateFormSubmissionsTable extends Migration */ public function up() { - Schema::create('form_submissions', function (Blueprint $table) { + $driver = DB::getDriverName(); + + Schema::create('form_submissions', function (Blueprint $table) use ($driver) { $table->id(); $table->foreignIdFor(\App\Models\Forms\Form::class,'form_id'); - $table->jsonb('data')->default(new Expression("(JSON_OBJECT())")); + if ($driver === 'mysql') { + $table->jsonb('data')->default(new Expression("(JSON_OBJECT())")); + } else { + $table->jsonb('data')->default("{}"); + } $table->timestamps(); }); } diff --git a/database/migrations/2022_05_10_144947_form_statistic.php b/database/migrations/2022_05_10_144947_form_statistic.php index 295e093..7cafb53 100644 --- a/database/migrations/2022_05_10_144947_form_statistic.php +++ b/database/migrations/2022_05_10_144947_form_statistic.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,10 +15,16 @@ return new class extends Migration */ public function up() { - Schema::create('form_statistics', function (Blueprint $table) { + $driver = DB::getDriverName(); + + Schema::create('form_statistics', function (Blueprint $table) use ($driver) { $table->id(); $table->foreignIdFor(\App\Models\Forms\Form::class,'form_id'); - $table->jsonb('data')->default(new Expression("(JSON_OBJECT())")); + if ($driver === 'mysql') { + $table->jsonb('data')->default(new Expression("(JSON_OBJECT())")); + } else { + $table->jsonb('data')->default("{}"); + } $table->date('date'); }); } diff --git a/database/migrations/2022_08_18_133641_add_removed_properties_to_forms.php b/database/migrations/2022_08_18_133641_add_removed_properties_to_forms.php index 263052c..03389a2 100644 --- a/database/migrations/2022_08_18_133641_add_removed_properties_to_forms.php +++ b/database/migrations/2022_08_18_133641_add_removed_properties_to_forms.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,8 +15,14 @@ return new class extends Migration */ public function up() { - Schema::table('forms', function (Blueprint $table) { - $table->jsonb('removed_properties')->default(new Expression("(JSON_ARRAY())")); + $driver = DB::getDriverName(); + + Schema::table('forms', function (Blueprint $table) use ($driver) { + if ($driver === 'mysql') { + $table->jsonb('removed_properties')->default(new Expression("(JSON_ARRAY())")); + } else { + $table->jsonb('removed_properties')->default("[]"); + } }); } diff --git a/database/migrations/2022_09_22_092205_create_templates_table.php b/database/migrations/2022_09_22_092205_create_templates_table.php index 34cf3be..0f7094f 100644 --- a/database/migrations/2022_09_22_092205_create_templates_table.php +++ b/database/migrations/2022_09_22_092205_create_templates_table.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,14 +15,20 @@ return new class extends Migration */ public function up() { - Schema::create('templates', function (Blueprint $table) { + $driver = DB::getDriverName(); + + Schema::create('templates', function (Blueprint $table) use ($driver) { $table->id(); $table->timestamps(); $table->string('name'); $table->string('slug'); $table->text('description'); $table->string('image_url'); - $table->jsonb('structure')->default(new Expression("(JSON_OBJECT())")); + if ($driver === 'mysql') { + $table->jsonb('structure')->default(new Expression("(JSON_OBJECT())")); + } else { + $table->jsonb('structure')->default('{}'); + } }); } diff --git a/database/migrations/2022_09_26_084721_add_questions_to_templates.php b/database/migrations/2022_09_26_084721_add_questions_to_templates.php index dad19e1..1fd0c50 100644 --- a/database/migrations/2022_09_26_084721_add_questions_to_templates.php +++ b/database/migrations/2022_09_26_084721_add_questions_to_templates.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,8 +15,14 @@ return new class extends Migration */ public function up() { - Schema::table('templates', function (Blueprint $table) { - $table->jsonb('questions')->default(new Expression("(JSON_ARRAY())")); + $driver = DB::getDriverName(); + + Schema::table('templates', function (Blueprint $table) use ($driver) { + if ($driver === 'mysql') { + $table->jsonb('questions')->default(new Expression("(JSON_ARRAY())")); + } else { + $table->jsonb('questions')->default('[]'); + } }); } diff --git a/database/migrations/2023_07_20_073728_add_seo_meta_to_forms.php b/database/migrations/2023_07_20_073728_add_seo_meta_to_forms.php index 0a91a8a..01fa247 100644 --- a/database/migrations/2023_07_20_073728_add_seo_meta_to_forms.php +++ b/database/migrations/2023_07_20_073728_add_seo_meta_to_forms.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,8 +15,14 @@ return new class extends Migration */ public function up() { - Schema::table('forms', function (Blueprint $table) { - $table->json('seo_meta')->default(new Expression("(JSON_OBJECT())")); + $driver = DB::getDriverName(); + + Schema::table('forms', function (Blueprint $table) use ($driver) { + if ($driver === 'mysql') { + $table->json('seo_meta')->default(new Expression("(JSON_OBJECT())")); + } else { + $table->json('seo_meta')->default("{}"); + } }); } diff --git a/database/migrations/2023_08_23_100710_add_notification_settings_to_forms.php b/database/migrations/2023_08_23_100710_add_notification_settings_to_forms.php index 21f96d1..37f3202 100644 --- a/database/migrations/2023_08_23_100710_add_notification_settings_to_forms.php +++ b/database/migrations/2023_08_23_100710_add_notification_settings_to_forms.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,8 +15,14 @@ return new class extends Migration */ public function up() { - Schema::table('forms', function (Blueprint $table) { - $table->json('notification_settings')->default(new Expression("(JSON_OBJECT())"))->nullable(true); + $driver = DB::getDriverName(); + + Schema::table('forms', function (Blueprint $table) use ($driver) { + if ($driver === 'mysql') { + $table->json('notification_settings')->default(new Expression("(JSON_OBJECT())"))->nullable(true); + } else { + $table->json('notification_settings')->default('{}')->nullable(true); + } }); } diff --git a/database/migrations/2023_09_01_052507_add_fields_to_templates.php b/database/migrations/2023_09_01_052507_add_fields_to_templates.php index 2edfab3..a4b8e74 100644 --- a/database/migrations/2023_09_01_052507_add_fields_to_templates.php +++ b/database/migrations/2023_09_01_052507_add_fields_to_templates.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Expression; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,12 +15,31 @@ return new class extends Migration */ public function up() { - Schema::table('templates', function (Blueprint $table) { + $driver = DB::getDriverName(); + + Schema::table('templates', function (Blueprint $table) use ($driver) { $table->boolean('publicly_listed')->default(false); - $table->jsonb('industries')->default(new Expression("(JSON_ARRAY())")); - $table->jsonb('types')->default(new Expression("(JSON_ARRAY())")); + + if ($driver === 'mysql') { + $table->jsonb('industries')->default(new Expression("(JSON_ARRAY())")); + } else { + $table->jsonb('industries')->default('[]'); + } + + if ($driver === 'mysql') { + $table->jsonb('types')->default(new Expression("(JSON_ARRAY())")); + } else { + $table->jsonb('types')->default('[]'); + } + $table->string('short_description')->nullable(); - $table->jsonb('related_templates')->default(new Expression("(JSON_ARRAY())")); + + if ($driver === 'mysql') { + $table->jsonb('related_templates')->default(new Expression("(JSON_ARRAY())")); + } else { + $table->jsonb('related_templates')->default('[]'); + } + $table->string('image_url',500)->nullable()->change(); }); }