aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb5
-rw-r--r--db/migrate/20180316115003_add_custom_field_values_to_companies.rb5
-rw-r--r--db/schema.rb5
-rw-r--r--db/seeds/seed_helpers.rb12
-rw-r--r--db/seeds/stif.seeds.rb53
5 files changed, 40 insertions, 40 deletions
diff --git a/db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb b/db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb
new file mode 100644
index 000000000..e49be7e40
--- /dev/null
+++ b/db/migrate/20180313082623_add_custom_field_values_to_stop_areas.rb
@@ -0,0 +1,5 @@
+class AddCustomFieldValuesToStopAreas < ActiveRecord::Migration
+ def change
+ add_column :stop_areas, :custom_field_values, :jsonb
+ end
+end
diff --git a/db/migrate/20180316115003_add_custom_field_values_to_companies.rb b/db/migrate/20180316115003_add_custom_field_values_to_companies.rb
new file mode 100644
index 000000000..1791a6970
--- /dev/null
+++ b/db/migrate/20180316115003_add_custom_field_values_to_companies.rb
@@ -0,0 +1,5 @@
+class AddCustomFieldValuesToCompanies < ActiveRecord::Migration
+ def change
+ add_column :companies, :custom_field_values, :json
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d90bf7b6c..0f6f21b83 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -141,6 +141,7 @@ ActiveRecord::Schema.define(version: 20180319043333) do
t.text "import_xml"
t.datetime "created_at"
t.datetime "updated_at"
+ t.json "custom_field_values"
end
add_index "companies", ["line_referential_id"], name: "index_companies_on_line_referential_id", using: :btree
@@ -842,10 +843,8 @@ ActiveRecord::Schema.define(version: 20180319043333) do
t.integer "waiting_time"
t.string "kind"
t.jsonb "localized_names"
-
t.datetime "confirmed_at"
- t.json "custom_field_values"
-
+ t.jsonb "custom_field_values"
end
add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree
diff --git a/db/seeds/seed_helpers.rb b/db/seeds/seed_helpers.rb
new file mode 100644
index 000000000..8e47e10bd
--- /dev/null
+++ b/db/seeds/seed_helpers.rb
@@ -0,0 +1,12 @@
+class ActiveRecord::Base
+ def self.seed_by(key_attribute, &block)
+ model = find_or_create_by! key_attribute
+ print "Seed #{name} #{key_attribute.inspect} "
+ yield model
+
+ puts "[#{(model.changed? ? 'updated' : 'no change')}]"
+ model.save!
+
+ model
+ end
+end
diff --git a/db/seeds/stif.seeds.rb b/db/seeds/stif.seeds.rb
index aa87b6f6c..bb73b0b9c 100644
--- a/db/seeds/stif.seeds.rb
+++ b/db/seeds/stif.seeds.rb
@@ -1,46 +1,25 @@
# coding: utf-8
-# This file should contain all the record creation needed to seed the database with its default values.
-# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
-stop_area_referential = StopAreaReferential.find_or_create_by!(name: "Reflex", objectid_format: "stif_netex")
-line_referential = LineReferential.find_or_create_by!(name: "CodifLigne", objectid_format: "stif_netex")
+require_relative 'seed_helpers'
-workgroup = Workgroup.find_or_create_by!(name: "Gestion de l'offre théorique IDFm") do |w|
- w.line_referential = line_referential
- w.stop_area_referential = stop_area_referential
- w.export_types = ["Export::Netex"]
+stif = Organisation.seed_by(code: "STIF") do |o|
+ o.name = 'STIF'
end
-Workbench.update_all workgroup_id: workgroup
-
-# Organisations
-stif = Organisation.find_or_create_by!(code: "STIF") do |org|
- org.name = 'STIF'
+stop_area_referential = StopAreaReferential.seed_by(name: "Reflex") do |r|
+ r.objectid_format = "stif_netex"
+ r.add_member stif, owner: true
end
-# operator = Organisation.find_or_create_by!(code: 'transporteur-a') do |organisation|
-# organisation.name = "Transporteur A"
-# end
-
-# Member
-line_referential.add_member stif, owner: true
-# line_referential.add_member operator
-stop_area_referential.add_member stif, owner: true
-# stop_area_referential.add_member operator
+line_referential = LineReferential.seed_by(name: "CodifLigne") do |r|
+ r.objectid_format = "stif_netex"
+ r.add_member stif, owner: true
+end
-# Users
-# stif.users.find_or_create_by!(username: "admin") do |user|
-# user.email = 'stif-boiv@af83.com'
-# user.password = "secret"
-# user.name = "STIF Administrateur"
-# end
-#
-# operator.users.find_or_create_by!(username: "transporteur") do |user|
-# user.email = 'stif-boiv+transporteur@af83.com'
-# user.password = "secret"
-# user.name = "Martin Lejeune"
-# end
+workgroup = Workgroup.seed_by(name: "Gestion de l'offre théorique IDFm") do |w|
+ w.line_referential = line_referential
+ w.stop_area_referential = stop_area_referential
+ w.export_types = ["Export::Netex"]
+end
-# Include all Lines in organisation functional_scope
-stif.update sso_attributes: { functional_scope: line_referential.lines.pluck(:objectid) }
-#operator.update sso_attributes: { functional_scope: line_referential.lines.limit(3).pluck(:objectid) }
+Workbench.update_all workgroup_id: workgroup