Skip to content

Commit

Permalink
Mejora funcion cambiar_cotejacion para poder quitar cotejacion a colu…
Browse files Browse the repository at this point in the history
  • Loading branch information
vtamara committed Apr 23, 2024
1 parent ceeaded commit d6362cc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/helpers/msip/sql_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
module Msip
module SqlHelper
# Pone cotejación dada a una columna tipo varchar (longitud long)
# Si la cotejación es nil o "" quita la posible cotejación
# que la columna tuviera
def cambiar_cotejacion(tabla, columna, long, cotejacion)
ActiveRecord::Base.connection.execute(<<-SQL.squish)
ALTER TABLE #{tabla}
ALTER COLUMN #{columna} SET DATA TYPE#{" "}
VARCHAR(#{long.to_i}) COLLATE "#{cotejacion}";
SQL
orden = "ALTER TABLE #{tabla} "\
"ALTER COLUMN #{columna} "\
"SET DATA TYPE VARCHAR(#{long.to_i})"
if !cotejacion.nil? && cotejacion != ""
orden += " COLLATE \"#{cotejacion}\";"
end
ActiveRecord::Base.connection.execute(orden)
end
module_function :cambiar_cotejacion

Expand Down

0 comments on commit d6362cc

Please sign in to comment.