From cdf0685c67721e0f4686e205379a00883506800f Mon Sep 17 00:00:00 2001 From: f Date: Fri, 16 Feb 2024 14:53:05 -0300 Subject: [PATCH] feat: asociar rol con deploy nos permite acceder al token --- app/models/deploy.rb | 2 ++ app/models/rol.rb | 1 + .../20240216170202_add_rol_to_deploys.rb | 18 ++++++++++++++++++ db/structure.sql | 6 ++++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240216170202_add_rol_to_deploys.rb diff --git a/app/models/deploy.rb b/app/models/deploy.rb index 1f087eb3..8f28f214 100644 --- a/app/models/deploy.rb +++ b/app/models/deploy.rb @@ -10,6 +10,8 @@ require 'open3' # :attributes`. class Deploy < ApplicationRecord belongs_to :site + belongs_to :rol + has_many :build_stats, dependent: :destroy DEPENDENCIES = [] diff --git a/app/models/rol.rb b/app/models/rol.rb index 37332400..c9a92515 100644 --- a/app/models/rol.rb +++ b/app/models/rol.rb @@ -11,6 +11,7 @@ class Rol < ApplicationRecord belongs_to :usuarie belongs_to :site + has_many :deploys validates_inclusion_of :rol, in: ROLES diff --git a/db/migrate/20240216170202_add_rol_to_deploys.rb b/db/migrate/20240216170202_add_rol_to_deploys.rb new file mode 100644 index 00000000..5f629432 --- /dev/null +++ b/db/migrate/20240216170202_add_rol_to_deploys.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Establece una relaciĆ³n entre roles y deploys +class AddRolToDeploys < ActiveRecord::Migration[6.1] + def up + add_column :deploys, :rol_id, :integer, index: true + + Deploy.find_each do |deploy| + rol_id = deploy.site.roles.find_by(rol: 'usuarie', temporal: false).id + + deploy.update_column(:rol_id, rol_id) if rol_id + end + end + + def down + remove_column :deploys, :rol_id + end +end diff --git a/db/structure.sql b/db/structure.sql index cb085f63..dede286d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -759,7 +759,8 @@ CREATE TABLE public.deploys ( updated_at timestamp without time zone NOT NULL, site_id integer, type character varying, - "values" text + "values" text, + rol_id integer ); @@ -2318,6 +2319,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230731195050'), ('20230829204127'), ('20230921155401'), -('20230927153926'); +('20230927153926'), +('20240216170202');