fix: migrations not passing on pgsql (#242)

* fix: migration not passing on pgsql

* pin postgres version
This commit is contained in:
Nicolas Hedger 2023-11-16 12:28:04 +01:00 committed by GitHub
parent c51d7397fa
commit 0960af0373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 97 additions and 21 deletions

View File

@ -12,7 +12,7 @@ jobs:
services: services:
postgres: postgres:
# Docker Hub image # Docker Hub image
image: postgres image: postgres:14
# Provide the password for postgres # Provide the password for postgres
env: env:
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateFormsTable extends Migration class CreateFormsTable extends Migration
@ -14,7 +15,9 @@ class CreateFormsTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('forms', function (Blueprint $table) { $driver = DB::getDriverName();
Schema::create('forms', function (Blueprint $table) use ($driver) {
$table->id(); $table->id();
$table->foreignIdFor(\App\Models\Workspace::class,'workspace_id'); $table->foreignIdFor(\App\Models\Workspace::class,'workspace_id');
$table->string('title'); $table->string('title');
@ -52,7 +55,11 @@ class CreateFormsTable extends Migration
$table->boolean('can_be_indexed')->default(true); $table->boolean('can_be_indexed')->default(true);
$table->string('password')->nullable()->default(null); $table->string('password')->nullable()->default(null);
$table->string('notification_sender')->default("OpenForm"); $table->string('notification_sender')->default("OpenForm");
if ($driver === 'mysql') {
$table->jsonb('tags')->default(new Expression('(JSON_ARRAY())')); $table->jsonb('tags')->default(new Expression('(JSON_ARRAY())'));
} else {
$table->jsonb('tags')->default('[]');
}
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateFormSubmissionsTable extends Migration class CreateFormSubmissionsTable extends Migration
@ -14,10 +15,16 @@ class CreateFormSubmissionsTable extends Migration
*/ */
public function up() 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->id();
$table->foreignIdFor(\App\Models\Forms\Form::class,'form_id'); $table->foreignIdFor(\App\Models\Forms\Form::class,'form_id');
if ($driver === 'mysql') {
$table->jsonb('data')->default(new Expression("(JSON_OBJECT())")); $table->jsonb('data')->default(new Expression("(JSON_OBJECT())"));
} else {
$table->jsonb('data')->default("{}");
}
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
@ -14,10 +15,16 @@ return new class extends Migration
*/ */
public function up() 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->id();
$table->foreignIdFor(\App\Models\Forms\Form::class,'form_id'); $table->foreignIdFor(\App\Models\Forms\Form::class,'form_id');
if ($driver === 'mysql') {
$table->jsonb('data')->default(new Expression("(JSON_OBJECT())")); $table->jsonb('data')->default(new Expression("(JSON_OBJECT())"));
} else {
$table->jsonb('data')->default("{}");
}
$table->date('date'); $table->date('date');
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
@ -14,8 +15,14 @@ return new class extends Migration
*/ */
public function up() public function up()
{ {
Schema::table('forms', function (Blueprint $table) { $driver = DB::getDriverName();
Schema::table('forms', function (Blueprint $table) use ($driver) {
if ($driver === 'mysql') {
$table->jsonb('removed_properties')->default(new Expression("(JSON_ARRAY())")); $table->jsonb('removed_properties')->default(new Expression("(JSON_ARRAY())"));
} else {
$table->jsonb('removed_properties')->default("[]");
}
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
@ -14,14 +15,20 @@ return new class extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('templates', function (Blueprint $table) { $driver = DB::getDriverName();
Schema::create('templates', function (Blueprint $table) use ($driver) {
$table->id(); $table->id();
$table->timestamps(); $table->timestamps();
$table->string('name'); $table->string('name');
$table->string('slug'); $table->string('slug');
$table->text('description'); $table->text('description');
$table->string('image_url'); $table->string('image_url');
if ($driver === 'mysql') {
$table->jsonb('structure')->default(new Expression("(JSON_OBJECT())")); $table->jsonb('structure')->default(new Expression("(JSON_OBJECT())"));
} else {
$table->jsonb('structure')->default('{}');
}
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
@ -14,8 +15,14 @@ return new class extends Migration
*/ */
public function up() public function up()
{ {
Schema::table('templates', function (Blueprint $table) { $driver = DB::getDriverName();
Schema::table('templates', function (Blueprint $table) use ($driver) {
if ($driver === 'mysql') {
$table->jsonb('questions')->default(new Expression("(JSON_ARRAY())")); $table->jsonb('questions')->default(new Expression("(JSON_ARRAY())"));
} else {
$table->jsonb('questions')->default('[]');
}
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
@ -14,8 +15,14 @@ return new class extends Migration
*/ */
public function up() public function up()
{ {
Schema::table('forms', function (Blueprint $table) { $driver = DB::getDriverName();
Schema::table('forms', function (Blueprint $table) use ($driver) {
if ($driver === 'mysql') {
$table->json('seo_meta')->default(new Expression("(JSON_OBJECT())")); $table->json('seo_meta')->default(new Expression("(JSON_OBJECT())"));
} else {
$table->json('seo_meta')->default("{}");
}
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
@ -14,8 +15,14 @@ return new class extends Migration
*/ */
public function up() public function up()
{ {
Schema::table('forms', function (Blueprint $table) { $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); $table->json('notification_settings')->default(new Expression("(JSON_OBJECT())"))->nullable(true);
} else {
$table->json('notification_settings')->default('{}')->nullable(true);
}
}); });
} }

View File

@ -3,6 +3,7 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression; use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
@ -14,12 +15,31 @@ return new class extends Migration
*/ */
public function up() 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->boolean('publicly_listed')->default(false);
if ($driver === 'mysql') {
$table->jsonb('industries')->default(new Expression("(JSON_ARRAY())")); $table->jsonb('industries')->default(new Expression("(JSON_ARRAY())"));
} else {
$table->jsonb('industries')->default('[]');
}
if ($driver === 'mysql') {
$table->jsonb('types')->default(new Expression("(JSON_ARRAY())")); $table->jsonb('types')->default(new Expression("(JSON_ARRAY())"));
} else {
$table->jsonb('types')->default('[]');
}
$table->string('short_description')->nullable(); $table->string('short_description')->nullable();
if ($driver === 'mysql') {
$table->jsonb('related_templates')->default(new Expression("(JSON_ARRAY())")); $table->jsonb('related_templates')->default(new Expression("(JSON_ARRAY())"));
} else {
$table->jsonb('related_templates')->default('[]');
}
$table->string('image_url',500)->nullable()->change(); $table->string('image_url',500)->nullable()->change();
}); });
} }