Skip to content

Commit

Permalink
Mejora migraciones. Closes #714
Browse files Browse the repository at this point in the history
  • Loading branch information
vtamara committed Oct 6, 2024
1 parent bb7ee26 commit bc8c5a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 3 additions & 3 deletions db/migrate/20241005013800_agrega_presp_empresas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def up
UPDATE sivel2_gen_victima SET organizacionarmada='41'
WHERE organizacionarmada=#{acemp.id};
UPDATE sivel2_gen_acto SET presponsable_id='41'
WHERE presponsablea_id=#{acemp.id};
WHERE presponsable_id=#{acemp.id};
UPDATE sivel2_gen_actocolectivo SET presponsable_id='41'
WHERE presponsablea_id=#{acemp.id};
WHERE presponsable_id=#{acemp.id};
UPDATE sivel2_gen_combatiente SET organizacionarmada='41'
WHERE organizacionarmada=#{acemp.id};
SQL
acemp.destroy_all
acemp.delete
else
crea_empresas
end
Expand Down
13 changes: 7 additions & 6 deletions db/migrate/20241006115708_completa_organizacion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ def renumera_organizacion(id_ant, id_nuevo)


def up
if Sivel2Gen::Organizacion.where("nombre ILIKE 'DESPLAZADOS'").count == 1
desp = Sivel2Gen::Organizacion.where("nombre ILIKE 'DESPLAZADOS'").take
if Sivel2Gen::Organizacion.where("TRIM(nombre) ILIKE 'DESPLAZADOS'").count == 1
desp = Sivel2Gen::Organizacion.where("TRIM(nombre) ILIKE 'DESPLAZADOS'").take
desp.nombre += "cadena_loca¿"
desp.save!
crea_desplazados
renumera_organizacion(desp.id, 19)
desp.destroy_all
desp.delete
else
crea_desplazados
end


if Sivel2Gen::Organizacion.where(id: 17).count == 0
execute <<-SQL
INSERT INTO public.sivel2_gen_organizacion (id, nombre, fechacreacion, fechadeshabilitacion, created_at, updated_at, observaciones) VALUES (17, 'VÍCTIMAS', '2013-07-05', NULL, '2013-07-05 00:00:00', '2013-07-05 00:00:00', NULL);
Expand All @@ -79,7 +80,7 @@ def up
vic.nombre += "cadena_loca¿"
vic.save!
renumera_organizacion(vic.id, 17)
vic.destroy_all
vic.delete
end

if Sivel2Gen::Organizacion.where("nombre ILIKE 'PAZ'").count == 1
Expand All @@ -88,7 +89,7 @@ def up
paz.save!
crea_paz
renumera_organizacion(paz.id, 20)
paz.destroy_all
paz.delete
else
crea_paz
end
Expand All @@ -98,7 +99,7 @@ def up
comunal.save!
crea_comunal
renumera_organizacion(comunal.id, 21)
comunal.destroy_all
comunal.delete
else
crea_comunal
end
Expand Down
10 changes: 10 additions & 0 deletions test/dummy/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8249,6 +8249,14 @@ ALTER TABLE ONLY public.sivel2_gen_caso_presponsable
ADD CONSTRAINT presuntos_responsables_caso_id_p_responsable_fkey FOREIGN KEY (presponsable_id) REFERENCES public.sivel2_gen_presponsable(id);


--
-- Name: sivel2_gen_presponsable presuntos_responsables_id_papa_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sivel2_gen_presponsable
ADD CONSTRAINT presuntos_responsables_id_papa_fkey FOREIGN KEY (papa_id) REFERENCES public.sivel2_gen_presponsable(id);


--
-- Name: sivel2_gen_profesion_victimacolectiva profesion_victimacolectiva_id_profesion_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -8544,6 +8552,7 @@ ALTER TABLE ONLY public.sivel2_gen_victimacolectiva_vinculoestado
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
('20241006115708'),
('20241005013833'),
('20241005013800'),
('20240806082036'),
Expand Down Expand Up @@ -8632,6 +8641,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220713200101'),
('20220613224844'),
('20220608044102'),
('20220601111520'),
('20220525122150'),
('20220428145059'),
('20220422190546'),
Expand Down

0 comments on commit bc8c5a6

Please sign in to comment.