mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 04:06:21 +00:00
Migrar los dominios canónicos
This commit is contained in:
parent
64d7fb6df0
commit
ded2b97702
1 changed files with 9 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue