mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 15:26:22 +00:00
Eliminar los hostnames duplicados
This commit is contained in:
parent
cb0308e3fc
commit
f664cce0da
1 changed files with 15 additions and 2 deletions
|
@ -7,7 +7,7 @@ module AddValuesToDeploy
|
||||||
included do
|
included do
|
||||||
store :values, accessors: %i[hostname onion], coder: JSON
|
store :values, accessors: %i[hostname onion], coder: JSON
|
||||||
|
|
||||||
puts "XXX: Al incluir este módulo todas las migraciones siguientes van a fallar. Podés correrlas de nuevo para arreglarlas."
|
puts 'XXX: Al incluir este módulo todas las migraciones siguientes van a fallar. Podés correrlas de nuevo para arreglarlas.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,7 +34,9 @@ class AddHostnameToDeploys < ActiveRecord::Migration[6.1]
|
||||||
site.name = site.name.split('.', 2).first if site.name.include?('.')
|
site.name = site.name.split('.', 2).first if site.name.include?('.')
|
||||||
|
|
||||||
site.deploys.find_each do |deploy|
|
site.deploys.find_each do |deploy|
|
||||||
hostname = (deploy.values[:onion] || deploy.values[:hostname] || deploy.hostname || "#{SecureRandom.hex}.invalid").dup.sub(/\.\z/, '')
|
hostname = (deploy.values[:onion] || deploy.values[:hostname] || deploy.hostname || "#{SecureRandom.hex}.invalid").dup.sub(
|
||||||
|
/\.\z/, ''
|
||||||
|
)
|
||||||
deploy.update_columns hostname_tmp: hostname
|
deploy.update_columns hostname_tmp: hostname
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,6 +44,17 @@ class AddHostnameToDeploys < ActiveRecord::Migration[6.1]
|
||||||
rename_column :deploys, :hostname_tmp, :hostname
|
rename_column :deploys, :hostname_tmp, :hostname
|
||||||
remove_column :deploys, :values
|
remove_column :deploys, :values
|
||||||
|
|
||||||
|
# Eliminar los dominios duplicados para un mismo sitio, siempre
|
||||||
|
# y cuando no sean DeployLocal.
|
||||||
|
columns = %i[site_id hostname]
|
||||||
|
Deploy.group(*columns).pluck(*columns).each do |duplicated|
|
||||||
|
deploys = Deploy.where(columns.zip(duplicated).to_h).order(:created_at).pluck(:id, :type)
|
||||||
|
|
||||||
|
next unless deploys.size > 1
|
||||||
|
|
||||||
|
Deploy.where(id: deploys.reject { |d| d.last == 'DeployLocal' }.map(&:first)).delete_all
|
||||||
|
end
|
||||||
|
|
||||||
add_index :deploys, :hostname, unique: true
|
add_index :deploys, :hostname, unique: true
|
||||||
# A esta altura todos los dominios deberían estar migrados.
|
# A esta altura todos los dominios deberían estar migrados.
|
||||||
change_column :deploys, :hostname, :string, null: false
|
change_column :deploys, :hostname, :string, null: false
|
||||||
|
|
Loading…
Reference in a new issue