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:
postgres:
# Docker Hub image
image: postgres
image: postgres:14
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres

View File

@ -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('[]');
}
});
}

View File

@ -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();
});
}

View File

@ -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');
});
}

View File

@ -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("[]");
}
});
}

View File

@ -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('{}');
}
});
}

View File

@ -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('[]');
}
});
}

View File

@ -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("{}");
}
});
}

View File

@ -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);
}
});
}

View File

@ -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();
});
}