From ded2b977020329f7f963915a4295ab312d44d480 Mon Sep 17 00:00:00 2001 From: f Date: Sun, 12 Sep 2021 21:55:46 -0300 Subject: [PATCH] =?UTF-8?q?Migrar=20los=20dominios=20can=C3=B3nicos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20210809155434_add_canonical_deploy_to_sites.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/db/migrate/20210809155434_add_canonical_deploy_to_sites.rb b/db/migrate/20210809155434_add_canonical_deploy_to_sites.rb index f0b24053..79b6af96 100644 --- a/db/migrate/20210809155434_add_canonical_deploy_to_sites.rb +++ b/db/migrate/20210809155434_add_canonical_deploy_to_sites.rb @@ -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