preserve template fields per submission
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddTemplateFieldsToSubmission < ActiveRecord::Migration[7.0]
|
||||
class MigrationTemplate < ApplicationRecord
|
||||
self.table_name = 'templates'
|
||||
end
|
||||
|
||||
class MigrationSubmission < ApplicationRecord
|
||||
self.table_name = 'submissions'
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :submissions, :template_fields, :text
|
||||
add_column :submissions, :template_schema, :text
|
||||
add_column :submissions, :template_submitters, :text
|
||||
|
||||
MigrationTemplate.all.each do |template|
|
||||
MigrationSubmission.where(template_id: template.id).each do |submission|
|
||||
submission.update_columns(template_fields: template.fields,
|
||||
template_schema: template.schema,
|
||||
template_submitters: template.submitters)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :submissions, :template_fields
|
||||
remove_column :submissions, :template_schema
|
||||
remove_column :submissions, :template_submitters
|
||||
end
|
||||
end
|
||||
+4
-1
@@ -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_07_01_075115) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_07_26_062428) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@@ -77,6 +77,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_01_075115) do
|
||||
t.datetime "deleted_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "template_fields"
|
||||
t.text "template_schema"
|
||||
t.text "template_submitters"
|
||||
t.index ["created_by_user_id"], name: "index_submissions_on_created_by_user_id"
|
||||
t.index ["template_id"], name: "index_submissions_on_template_id"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user