5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 23:46:22 +00:00

Migrar los dominios canónicos

This commit is contained in:
f 2021-09-12 21:55:46 -03:00
parent 64d7fb6df0
commit ded2b97702

View file

@ -8,16 +8,22 @@
# después, pero la idea es que nunca haya ceros.
class AddCanonicalDeployToSites < ActiveRecord::Migration[6.1]
def up
add_belongs_to :sites, :canonical_deploy, index: true, null: false, default: 0
add_belongs_to :sites, :canonical_deploy, index: true
# Si el sitio tenía un dominio alternativo, usar ese en lugar del
# local, asumiendo que es el primero de todos los posibles.
Site.find_each do |site|
deploy = site.deploys.order(created_at: :asc).find_by_type('DeployAlternativeDomain')
if site.name.end_with? '.'
deploy = site.deploys.find_or_create_by(type: 'DeployAlternativeDomain', hostname: site.name.sub(/\.\z/, ''))
end
deploy ||= site.deploys.order(created_at: :asc).find_by_type('DeployAlternativeDomain')
deploy ||= site.deploy_local
site.update canonical_deploy_id: deploy.id
site.update_columns canonical_deploy_id: deploy.id
end
change_column :sites, :canonical_deploy_id, :bigint, null: false
end
def down