From 273bc81f2dd9b2d295b06de76cd089c17f363941 Mon Sep 17 00:00:00 2001 From: David Biddle Date: Fri, 17 Nov 2023 11:13:33 +0000 Subject: [PATCH] Add empty WHN markdown field and update existing live forms --- ...add_what_happens_next_markdown_to_forms.rb | 23 +++++++++++++++++++ db/schema.rb | 3 ++- spec/models/form_spec.rb | 1 + spec/request/api/v1/forms_controller_spec.rb | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20231116142411_add_what_happens_next_markdown_to_forms.rb diff --git a/db/migrate/20231116142411_add_what_happens_next_markdown_to_forms.rb b/db/migrate/20231116142411_add_what_happens_next_markdown_to_forms.rb new file mode 100644 index 00000000..f2019c10 --- /dev/null +++ b/db/migrate/20231116142411_add_what_happens_next_markdown_to_forms.rb @@ -0,0 +1,23 @@ +class AddWhatHappensNextMarkdownToForms < ActiveRecord::Migration[7.0] + def change + add_column :forms, :what_happens_next_markdown, :text + + reversible do |direction| + Form.find_each do |form| + if form.made_live_forms.present? + made_live_form = form.made_live_forms.last + form_blob = JSON.parse(made_live_form.json_form_blob, symbolize_names: true) + + direction.up do + form_blob[:what_happens_next_markdown] = nil + end + direction.down do + form_blob.delete(:what_happens_next_markdown) + end + + made_live_form.update!(json_form_blob: form_blob.to_json) + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index aca5d4f9..87aeeda4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_08_24_153800) do +ActiveRecord::Schema[7.0].define(version: 2023_11_16_142411) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -55,6 +55,7 @@ t.datetime "updated_at", null: false t.bigint "creator_id" t.bigint "organisation_id" + t.text "what_happens_next_markdown" end create_table "made_live_forms", force: :cascade do |t| diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 7c23a60b..f93732ca 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -261,6 +261,7 @@ "declaration_section_completed", "pages", "page_order", + "what_happens_next_markdown", ) end end diff --git a/spec/request/api/v1/forms_controller_spec.rb b/spec/request/api/v1/forms_controller_spec.rb index eb117715..8494b356 100644 --- a/spec/request/api/v1/forms_controller_spec.rb +++ b/spec/request/api/v1/forms_controller_spec.rb @@ -195,6 +195,7 @@ form_slug: "test-form-1", start_page: nil, what_happens_next_text: nil, + what_happens_next_markdown: nil, support_email: nil, support_phone: nil, support_url: nil,