add revisions

This commit is contained in:
Pete Matsyburka
2026-05-07 09:48:25 +03:00
parent 04ec2f8260
commit 10fd624bec
16 changed files with 462 additions and 17 deletions
+1
View File
@@ -70,6 +70,7 @@ class Template < ApplicationRecord
has_many :submissions, dependent: :destroy
has_many :template_sharings, dependent: :destroy
has_many :template_accesses, dependent: :destroy
has_many :template_versions, dependent: :destroy
has_many :dynamic_documents, dependent: :destroy
has_many :dynamic_document_versions, through: :dynamic_documents, source: :versions
+44
View File
@@ -0,0 +1,44 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: template_versions
#
# id :bigint not null, primary key
# data :text not null
# sha1 :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# author_id :bigint not null
# template_id :bigint not null
#
# Indexes
#
# index_template_versions_on_account_id (account_id)
# index_template_versions_on_author_id (author_id)
# index_template_versions_on_template_id_and_sha1 (template_id,sha1) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (author_id => users.id)
# fk_rails_... (template_id => templates.id)
#
class TemplateVersion < ApplicationRecord
belongs_to :template
belongs_to :account
belongs_to :author, class_name: 'User'
attribute :data, :string, default: -> { {} }
serialize :data, coder: JSON
before_validation :set_account, on: :create
private
def set_account
self.account ||= template.account
end
end