diff --git a/app/models/template.rb b/app/models/template.rb index d3802f05..73c54313 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -4,22 +4,23 @@ # # Table name: templates # -# id :bigint not null, primary key -# archived_at :datetime -# fields :text not null -# name :string not null -# preferences :text not null -# schema :text not null -# shared_link :boolean default(FALSE), not null -# slug :string not null -# source :text not null -# submitters :text not null -# created_at :datetime not null -# updated_at :datetime not null -# account_id :integer not null -# author_id :integer not null -# external_id :string -# folder_id :integer not null +# id :bigint not null, primary key +# archived_at :datetime +# external_data_fields :string +# fields :text not null +# name :string not null +# preferences :text not null +# schema :text not null +# shared_link :boolean default(FALSE), not null +# slug :string not null +# source :text not null +# submitters :text not null +# created_at :datetime not null +# updated_at :datetime not null +# account_id :integer not null +# author_id :integer not null +# external_id :string +# folder_id :integer not null # # Indexes # @@ -78,6 +79,12 @@ class Template < ApplicationRecord external_id end + def external_data_fields + return {} if self[:external_data_fields].blank? + + JSON.parse(self[:external_data_fields]) + end + private def maybe_set_default_folder diff --git a/db/migrate/20250703143236_add_external_data_fields_to_templates.rb b/db/migrate/20250703143236_add_external_data_fields_to_templates.rb new file mode 100644 index 00000000..f286278c --- /dev/null +++ b/db/migrate/20250703143236_add_external_data_fields_to_templates.rb @@ -0,0 +1,5 @@ +class AddExternalDataFieldsToTemplates < ActiveRecord::Migration[8.0] + def change + add_column :templates, :external_data_fields, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 7bc96f6e..d2f8780d 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[8.0].define(version: 2025_07_02_204317) do +ActiveRecord::Schema[8.0].define(version: 2025_07_03_143236) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_catalog.plpgsql" @@ -393,6 +393,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_07_02_204317) do t.string "external_id" t.text "preferences", null: false t.boolean "shared_link", default: false, null: false + t.string "external_data_fields" t.index ["account_id", "folder_id", "id"], name: "index_templates_on_account_id_and_folder_id_and_id", where: "(archived_at IS NULL)" t.index ["account_id", "id"], name: "index_templates_on_account_id_and_id_archived", where: "(archived_at IS NOT NULL)" t.index ["account_id"], name: "index_templates_on_account_id"