mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
496 B
21 lines
496 B
# 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 |