aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrate
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20170213135212_add_timestamps_to_some_models.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/db/migrate/20170213135212_add_timestamps_to_some_models.rb b/db/migrate/20170213135212_add_timestamps_to_some_models.rb
index 1502975fe..c9fdb1d54 100644
--- a/db/migrate/20170213135212_add_timestamps_to_some_models.rb
+++ b/db/migrate/20170213135212_add_timestamps_to_some_models.rb
@@ -1,14 +1,21 @@
class AddTimestampsToSomeModels < ActiveRecord::Migration
- def change
+ def up
models = %i(vehicle_journeys timebands time_tables stop_points stop_areas routing_constraint_zones routes route_sections pt_links networks lines
journey_patterns group_of_lines connection_links companies access_points access_links)
models.each do |table|
- if !column_exists?(table, :created_at) && column_exists?(table, :creation_time)
+ unless column_exists?(table, :created_at)
add_timestamps table
- Object.const_get("Chouette::#{table.to_s.classify}").update_all 'created_at = creation_time'
end
- remove_column table, :creation_time if column_exists?(table, :creation_time)
+
+ if column_exists?(table, :creation_time)
+ execute "update #{table} set created_at = creation_time"
+ remove_column table, :creation_time
+ end
end
end
+
+ def down
+
+ end
end