DEV: Introduce Migration::Helpers for new-site detection (#20934)

We use schema_migration_details to determine the age of a site in multiple migrations. This commit moves the logic into a dedicated `Migration::Helpers` module so that it doesn't need to be re-implemented every time.
This commit is contained in:
David Taylor
2023-04-03 12:46:39 +02:00
committed by GitHub
parent fd34032db2
commit f3402be262
4 changed files with 27 additions and 25 deletions

23
lib/migration/helpers.rb Normal file
View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
module Migration
module Helpers
def self.site_created_at
result = DB.query_single <<~SQL
SELECT created_at
FROM schema_migration_details
ORDER BY created_at
LIMIT 1
SQL
result.first
end
def self.existing_site?
site_created_at < 1.hour.ago
end
def self.new_site?
!old_site?
end
end
end