add external data fields to templates

pull/501/head
Mikhael Rakauskas 4 months ago
parent 9e542c7aaf
commit 1fc9d212ca

@ -4,22 +4,23 @@
# #
# Table name: templates # Table name: templates
# #
# id :bigint not null, primary key # id :bigint not null, primary key
# archived_at :datetime # archived_at :datetime
# fields :text not null # external_data_fields :string
# name :string not null # fields :text not null
# preferences :text not null # name :string not null
# schema :text not null # preferences :text not null
# shared_link :boolean default(FALSE), not null # schema :text not null
# slug :string not null # shared_link :boolean default(FALSE), not null
# source :text not null # slug :string not null
# submitters :text not null # source :text not null
# created_at :datetime not null # submitters :text not null
# updated_at :datetime not null # created_at :datetime not null
# account_id :integer not null # updated_at :datetime not null
# author_id :integer not null # account_id :integer not null
# external_id :string # author_id :integer not null
# folder_id :integer not null # external_id :string
# folder_id :integer not null
# #
# Indexes # Indexes
# #
@ -78,6 +79,12 @@ class Template < ApplicationRecord
external_id external_id
end end
def external_data_fields
return {} if self[:external_data_fields].blank?
JSON.parse(self[:external_data_fields])
end
private private
def maybe_set_default_folder def maybe_set_default_folder

@ -0,0 +1,5 @@
class AddExternalDataFieldsToTemplates < ActiveRecord::Migration[8.0]
def change
add_column :templates, :external_data_fields, :string
end
end

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "btree_gin" enable_extension "btree_gin"
enable_extension "pg_catalog.plpgsql" 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.string "external_id"
t.text "preferences", null: false t.text "preferences", null: false
t.boolean "shared_link", default: false, 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", "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", "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" t.index ["account_id"], name: "index_templates_on_account_id"

Loading…
Cancel
Save