Class: AddTimestamps

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
db/migrate/006_add_timestamps.rb

Overview

Adds 'created_at' and 'updated_at' columns to every primary table.

Constant Summary collapse

@@TABLES_NEEDING_RENAME =
[:clients, :hosts, :notes, :refs, :services, :vulns, :wmap_requests]
@@TABLES_NEEDING_CREATED_AT =
[:wmap_targets]
@@TABLES_NEEDING_UPDATED_AT =
[:clients, :events, :hosts, :notes, :refs, :services, :vulns, :wmap_requests, :wmap_targets]

Class Method Summary collapse

Class Method Details

.downObject



18
19
20
21
22
23
24
# File 'db/migrate/006_add_timestamps.rb', line 18

def self.down
	@@TABLES_NEEDING_RENAME.each { |t| rename_column t, :created_at, :created }
	
	@@TABLES_NEEDING_CREATED_AT.each { |t| remove_column t, :created_at }

	@@TABLES_NEEDING_UPDATED_AT.each { |t| remove_column t, :updated_at }
end

.upObject



10
11
12
13
14
15
16
# File 'db/migrate/006_add_timestamps.rb', line 10

def self.up
	@@TABLES_NEEDING_RENAME.each { |t| rename_column t, :created, :created_at }
	
	@@TABLES_NEEDING_CREATED_AT.each { |t| add_column t, :created_at, :datetime }

	@@TABLES_NEEDING_UPDATED_AT.each { |t| add_column t, :updated_at, :datetime }
end