mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 11:21:42 +00:00
Agregar created_at a access_logs para poder agrupar por fecha
This commit is contained in:
parent
094a8092de
commit
604c16bfb8
1 changed files with 18 additions and 0 deletions
18
db/migrate/20210807004941_add_create_at_to_access_logs.rb
Normal file
18
db/migrate/20210807004941_add_create_at_to_access_logs.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Cambia los msec a datetime para poder agregar por tiempos
|
||||
class AddCreateAtToAccessLogs < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :access_logs, :created_at, :datetime, precision: 6
|
||||
|
||||
create_trigger(compatibility: 1).on(:access_logs).before(:insert) do
|
||||
'new.created_at := to_timestamp(new.msec)'
|
||||
end
|
||||
|
||||
ActiveRecord::Base.connection.execute('update access_logs set created_at = to_timestamp(msec);')
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :access_logs, :created_at
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue