mirror of https://github.com/docusealco/docuseal
feat: add submission counts to templates view (closes #617)
parent
be27ce4161
commit
9007dd1d1f
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddSubmissionsCountToTemplates < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
add_column :templates, :submissions_count, :integer, default: 0, null: false
|
||||
|
||||
# Backfill existing counts
|
||||
execute <<~SQL.squish
|
||||
UPDATE templates
|
||||
SET submissions_count = (
|
||||
SELECT COUNT(*)
|
||||
FROM submissions
|
||||
WHERE submissions.template_id = templates.id
|
||||
)
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :templates, :submissions_count
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue