From b67193fbca8533ee0b798f63ac1b2721484ae790 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 1 Nov 2023 17:02:32 -0300 Subject: [PATCH 1/4] feat: soportar varias instancias de distributed press #14540 --- app/models/deploy_distributed_press.rb | 10 ++++++---- ...6_add_default_to_distributed_press_publisher.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb diff --git a/app/models/deploy_distributed_press.rb b/app/models/deploy_distributed_press.rb index 2c892b55..69c162aa 100644 --- a/app/models/deploy_distributed_press.rb +++ b/app/models/deploy_distributed_press.rb @@ -101,12 +101,14 @@ class DeployDistributedPress < Deploy # El cliente de la API # - # TODO: cuando soportemos más, tiene que haber una relación entre - # DeployDistributedPress y DistributedPressPublisher. - # # @return [DistributedPressPublisher] def publisher - @publisher ||= DistributedPressPublisher.last + @publisher ||= + if distributed_press_publisher_id + DistributedPressPublisher.find(distributed_press_publisher_id) + else + DistributedPressPublisher.find_by_default(true) + end end # El cliente para actualizar el sitio diff --git a/db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb b/db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb new file mode 100644 index 00000000..ada9392f --- /dev/null +++ b/db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Una instancia es la instancia por defecto +class AddDefaultToDistributedPressPublisher < ActiveRecord::Migration[6.1] + def up + add_column :distributed_press_publishers, :default, :boolean, default: false + + DistributedPressPublisher.last.update(default: true) + end + + def down + remove_column :distributed_press_publishers, :default + end +end From 5540232b7e46aa3ecaa3114d3d2d05079caf4abf Mon Sep 17 00:00:00 2001 From: f Date: Wed, 1 Nov 2023 17:09:32 -0300 Subject: [PATCH 2/4] fix: la instancia puede repetirse --- app/models/distributed_press_publisher.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/distributed_press_publisher.rb b/app/models/distributed_press_publisher.rb index 6139db93..4c3293e3 100644 --- a/app/models/distributed_press_publisher.rb +++ b/app/models/distributed_press_publisher.rb @@ -13,8 +13,8 @@ class DistributedPressPublisher < ApplicationRecord # @return [IO] attr_reader :logger_out - # La instancia es única - validates_uniqueness_of :instance + # La instancia es necesaria pero no única + validates_presence_of :instance # El token es necesario validates_presence_of :token From f5af85a66eaf822c1f6d3b4e987b9e3a909a4d60 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 1 Nov 2023 17:11:31 -0300 Subject: [PATCH 3/4] fix: guardar el id como JSON --- app/models/deploy_distributed_press.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/deploy_distributed_press.rb b/app/models/deploy_distributed_press.rb index 69c162aa..58fea294 100644 --- a/app/models/deploy_distributed_press.rb +++ b/app/models/deploy_distributed_press.rb @@ -13,7 +13,7 @@ require 'njalla/v1' # Al ser publicado, envía los archivos en un tarball y actualiza la # información. class DeployDistributedPress < Deploy - store :values, accessors: %i[hostname remote_site_id remote_info], coder: JSON + store :values, accessors: %i[hostname remote_site_id remote_info distributed_press_publisher_id], coder: JSON before_create :create_remote_site!, :create_njalla_records! before_destroy :delete_remote_site!, :delete_njalla_records! From 0975d8d5cf90c0af5265116d38be2051b37bd169 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 26 Mar 2024 15:48:30 -0300 Subject: [PATCH 4/4] fix: no fallar si no hay ninguno --- ...20231101200026_add_default_to_distributed_press_publisher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb b/db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb index ada9392f..fd833acb 100644 --- a/db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb +++ b/db/migrate/20231101200026_add_default_to_distributed_press_publisher.rb @@ -5,7 +5,7 @@ class AddDefaultToDistributedPressPublisher < ActiveRecord::Migration[6.1] def up add_column :distributed_press_publishers, :default, :boolean, default: false - DistributedPressPublisher.last.update(default: true) + DistributedPressPublisher.last&.update(default: true) end def down