aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-02-02 18:14:03 +0100
committerTeddy Wing2018-02-06 14:47:31 +0100
commit7d24256844e33bcb7875076a4bcfae22dd308009 (patch)
tree02b7cec8fe79473955e48731f78d6bcd1dcb0366
parent2913e072467ca0f9f93186e39e42e637b3e33152 (diff)
downloadchouette-core-7d24256844e33bcb7875076a4bcfae22dd308009.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
-rw-r--r--db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb11
-rw-r--r--db/schema.rb2
2 files changed, 12 insertions, 1 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
diff --git a/db/schema.rb b/db/schema.rb
index d54a40feb..cd4d42005 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180124124215) do
+ActiveRecord::Schema.define(version: 20180202170009) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"