From 92ebcfbb339ae2dc8f5ba719311f62da5102451f Mon Sep 17 00:00:00 2001 From: Gaurav Singh Date: Sun, 1 Oct 2023 00:10:36 +0530 Subject: [PATCH] fix : Added MySQL support #171 Signed-off-by: Gaurav Singh --- app/Models/Forms/Form.php | 16 ++++++++++++++++ app/Models/Forms/FormStatistic.php | 7 +++++++ app/Models/Forms/FormSubmission.php | 7 +++++++ app/Models/Template.php | 8 ++++++++ .../2021_05_19_140326_create_forms_table.php | 10 +++++----- ...5_24_234028_create_form_submissions_table.php | 2 +- .../2022_05_10_144947_form_statistic.php | 2 +- ...18_133641_add_removed_properties_to_forms.php | 2 +- .../2022_09_22_092205_create_templates_table.php | 2 +- ...2_09_26_084721_add_questions_to_templates.php | 2 +- ...ange_max_submissions_reached_text_to_text.php | 4 ++-- ...editable_submissions_button_text_to_forms.php | 2 +- .../2023_07_20_073728_add_seo_meta_to_forms.php | 2 +- ...100710_add_notification_settings_to_forms.php | 2 +- ...2023_09_01_052507_add_fields_to_templates.php | 6 +++--- 15 files changed, 56 insertions(+), 18 deletions(-) diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.php index 7ba3fcc9e..25d2484eb 100644 --- a/app/Models/Forms/Form.php +++ b/app/Models/Forms/Form.php @@ -123,6 +123,22 @@ class Form extends Model 'removed_properties' ]; + /** + * Default values + */ + protected $attributes = [ + 'submit_button_text' => 'Submit', + 're_fill_button_text' => 'Fill Again', + 'submitted_text' => 'Amazing, we saved your answers. Thank you for your time and have a great day!', + 'notification_body' => '

Hello there 👋
This is a confirmation that your submission was successfully saved.

', + 'tags' => '[]', + 'removed_properties' => '[]', + 'max_submissions_reached_text' => 'This form has now reached the maximum number of allowed submissions and is now closed.', + 'editable_submissions_button_text' => 'Edit submission', + 'seo_meta' => '{}', + 'notification_settings' => '{}' + ]; + /** * The event map for the model. * diff --git a/app/Models/Forms/FormStatistic.php b/app/Models/Forms/FormStatistic.php index 50b438874..d43497458 100644 --- a/app/Models/Forms/FormStatistic.php +++ b/app/Models/Forms/FormStatistic.php @@ -27,6 +27,13 @@ class FormStatistic extends Model 'data' => 'array', ]; + /** + * Set Default values + */ + protected $attributes = [ + 'data' => '{}' + ]; + /** * Relationships */ diff --git a/app/Models/Forms/FormSubmission.php b/app/Models/Forms/FormSubmission.php index ea2c40098..26fd986cf 100644 --- a/app/Models/Forms/FormSubmission.php +++ b/app/Models/Forms/FormSubmission.php @@ -18,6 +18,13 @@ class FormSubmission extends Model 'data' => 'array' ]; + /** + * Default values + */ + protected $attributes = [ + 'data' => '{}' + ]; + /** * RelationShips */ diff --git a/app/Models/Template.php b/app/Models/Template.php index 22d5c5fc9..b579411d7 100644 --- a/app/Models/Template.php +++ b/app/Models/Template.php @@ -37,8 +37,16 @@ class Template extends Model 'updated_at' => 'datetime', ]; + /** + * Default values + */ protected $attributes = [ 'publicly_listed' => false, + 'structure' => '{}', + 'questions' => '{}', + 'industries' => '[]', + 'types' => '[]', + 'related_templates' => '[]', ]; public function setDescriptionAttribute($value) 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 7622b9728..776b4ee05 100644 --- a/database/migrations/2021_05_19_140326_create_forms_table.php +++ b/database/migrations/2021_05_19_140326_create_forms_table.php @@ -22,14 +22,14 @@ public function up() $table->timestamps(); $table->boolean('notifies')->default(false); $table->text('description')->nullable(); - $table->text('submit_button_text')->default('Submit'); + $table->text('submit_button_text')->nullable(); $table->boolean('re_fillable')->default(false); - $table->text('re_fill_button_text')->default('Fill Again'); + $table->text('re_fill_button_text')->nullable(); $table->string('color')->default('#3B82F6'); $table->boolean('uppercase_labels')->default(true); $table->boolean('no_branding')->default(false); $table->boolean('hide_title')->default(false); - $table->text('submitted_text')->default('Amazing, we saved your answers. Thank you for your time and have a great day!'); + $table->text('submitted_text')->nullable(); $table->string('dark_mode')->default('auto'); $table->string('webhook_url')->nullable(); $table->boolean('send_submission_confirmation')->default(false); @@ -45,13 +45,13 @@ public function up() $table->timestamp('closes_at')->nullable(); $table->text('closed_text')->nullable(); $table->string('notification_subject')->default("We saved your answers"); - $table->text('notification_body')->default('

Hello there 👋
This is a confirmation that your submission was successfully saved.

'); + $table->text('notification_body')->nullable(); $table->boolean('notifications_include_submission')->default(true); $table->boolean('use_captcha')->default(false); $table->boolean('can_be_indexed')->default(true); $table->string('password')->nullable()->default(null); $table->string('notification_sender')->default("OpenForm"); - $table->jsonb('tags')->default('[]'); + $table->jsonb('tags')->nullable(); }); } 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 64cadd7d7..24be24906 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 @@ -16,7 +16,7 @@ public function up() Schema::create('form_submissions', function (Blueprint $table) { $table->id(); $table->foreignIdFor(\App\Models\Forms\Form::class,'form_id'); - $table->jsonb('data')->default('{}'); + $table->jsonb('data')->nullable(); $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 85ace26b7..0bc062f2c 100644 --- a/database/migrations/2022_05_10_144947_form_statistic.php +++ b/database/migrations/2022_05_10_144947_form_statistic.php @@ -16,7 +16,7 @@ public function up() Schema::create('form_statistics', function (Blueprint $table) { $table->id(); $table->foreignIdFor(\App\Models\Forms\Form::class,'form_id'); - $table->jsonb('data')->default('{}'); + $table->jsonb('data')->nullable(); $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 19997ed5c..14b47b9ea 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 @@ -14,7 +14,7 @@ public function up() { Schema::table('forms', function (Blueprint $table) { - $table->jsonb('removed_properties')->default('[]'); + $table->jsonb('removed_properties')->nullable(); }); } 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 4642c5857..6e7996a4d 100644 --- a/database/migrations/2022_09_22_092205_create_templates_table.php +++ b/database/migrations/2022_09_22_092205_create_templates_table.php @@ -20,7 +20,7 @@ public function up() $table->string('slug'); $table->text('description'); $table->string('image_url'); - $table->jsonb('structure')->default('{}'); + $table->jsonb('structure')->nullable(); }); } 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 449fe40a9..8c83e8152 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 @@ -14,7 +14,7 @@ public function up() { Schema::table('templates', function (Blueprint $table) { - $table->jsonb('questions')->default('{}'); + $table->jsonb('questions')->nullable(); }); } diff --git a/database/migrations/2023_03_06_033440_change_max_submissions_reached_text_to_text.php b/database/migrations/2023_03_06_033440_change_max_submissions_reached_text_to_text.php index eb1504050..c5224b7fd 100644 --- a/database/migrations/2023_03_06_033440_change_max_submissions_reached_text_to_text.php +++ b/database/migrations/2023_03_06_033440_change_max_submissions_reached_text_to_text.php @@ -14,7 +14,7 @@ public function up() { Schema::table('forms', function (Blueprint $table) { - $table->text('max_submissions_reached_text')->nullable()->default('This form has now reached the maximum number of allowed submissions and is now closed.')->change(); + $table->text('max_submissions_reached_text')->nullable()->change(); }); } @@ -26,7 +26,7 @@ public function up() public function down() { Schema::table('forms', function (Blueprint $table) { - $table->string('max_submissions_reached_text')->nullable()->default('This form has now reached the maximum number of allowed submissions and is now closed.')->change(); + $table->string('max_submissions_reached_text')->nullable()->change(); }); } }; diff --git a/database/migrations/2023_03_13_094806_add_editable_submissions_button_text_to_forms.php b/database/migrations/2023_03_13_094806_add_editable_submissions_button_text_to_forms.php index e77e68b68..9c7c3f7f5 100644 --- a/database/migrations/2023_03_13_094806_add_editable_submissions_button_text_to_forms.php +++ b/database/migrations/2023_03_13_094806_add_editable_submissions_button_text_to_forms.php @@ -14,7 +14,7 @@ public function up() { Schema::table('forms', function (Blueprint $table) { - $table->text('editable_submissions_button_text')->default('Edit submission'); + $table->text('editable_submissions_button_text')->nullable(); }); } 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 e0a67d76b..933f9547d 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 @@ -14,7 +14,7 @@ public function up() { Schema::table('forms', function (Blueprint $table) { - $table->json('seo_meta')->default('{}'); + $table->json('seo_meta')->nullable(); }); } 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 b091f6b7f..14dd6d0ce 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 @@ -14,7 +14,7 @@ public function up() { Schema::table('forms', function (Blueprint $table) { - $table->json('notification_settings')->default('{}')->nullable(true); + $table->json('notification_settings')->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 3adfc833e..c40735aab 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 @@ -15,10 +15,10 @@ public function up() { Schema::table('templates', function (Blueprint $table) { $table->boolean('publicly_listed')->default(false); - $table->jsonb('industries')->default('[]'); - $table->jsonb('types')->default('[]'); + $table->jsonb('industries')->nullable(); + $table->jsonb('types')->nullable(); $table->string('short_description')->nullable(); - $table->jsonb('related_templates')->default('[]'); + $table->jsonb('related_templates')->nullable(); $table->string('image_url',500)->nullable()->change(); }); }