aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrate
diff options
context:
space:
mode:
authorTeddy Wing2018-02-02 18:14:03 +0100
committercedricnjanga2018-02-07 07:17:00 -0800
commit93ece87723191a33a830650cfa8c6cbc75470279 (patch)
tree4d8148286d28207511c6577e82a0d0685a7cacb1 /db/migrate
parenta5c48d95d78cf611985b0f3dc0d36c070d9f601e (diff)
downloadchouette-core-93ece87723191a33a830650cfa8c6cbc75470279.tar.bz2
Set all existing `StopArea`s with nil `kind`s to `:commercial`
The other migration for this in `db/migrate/20180126134944_add_kind_to_stop_areas.rb` didn't handle `kind IS NULL`. Since all the `kind`s were initialised to NULL when the column was created, the `where` query didn't select any stop areas because it was looking for those with some varchar value, and thus it wasn't able to update any. This ensures our existing records all have a `kind` in case we end up using the field in a template at some point and our old data bugs out. Refs #5817
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb b/db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb
new file mode 100644
index 000000000..6c6f6370e
--- /dev/null
+++ b/db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb
@@ -0,0 +1,11 @@
+class SetStopAreasKindToCommercialOnExistingRecords < ActiveRecord::Migration
+ def up
+ Chouette::StopArea
+ .where('kind != ? or kind is null', :non_commercial)
+ .update_all(kind: :commercial)
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end