diff --git a/db/migrate/20131019150459_create_bike_wheel_sizes.rb b/db/migrate/20131019150459_create_bike_wheel_sizes.rb index 96cb005..4e35a8a 100644 --- a/db/migrate/20131019150459_create_bike_wheel_sizes.rb +++ b/db/migrate/20131019150459_create_bike_wheel_sizes.rb @@ -10,10 +10,6 @@ class CreateBikeWheelSizes < ActiveRecord::Migration t.string :description t.string :tire_common_score end - - #create the default undetermined wheel size record - BikeWheelSize.create( twmm: 0, rdmm: 0, rdin: 0, twin: 0, rdfr: 0, twfr: 0, description: "UNDETERMINED", tire_common_score: 0) - ActiveRecord::Base.connection.execute(IO.read(File.join(Rails.root, "db", "seed", "sql", "common_wheel_sizes.sql"))) end def down diff --git a/db/seed/sql/common_wheel_sizes.sql b/db/seed/sql/common_wheel_sizes.sql index 2369454..98f4975 100644 --- a/db/seed/sql/common_wheel_sizes.sql +++ b/db/seed/sql/common_wheel_sizes.sql @@ -1,3 +1,6 @@ +PRAGMA foreign_keys=OFF; +BEGIN TRANSACTION; +INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_common_score) values (0,0,0,0,0,0,'UNDETERMINED',0); INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_common_score) values (54,110,'8 1/2','2','','','',1); INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_common_score) values (62,203,'12','1/2 x 2 1/4','320 ','57','',1); INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_common_score) values (47,305,'16','1,75 [x 2]','','','',1); @@ -35,3 +38,4 @@ INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_co INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_common_score) values (28,630,'27','1 1/8 [1 1/4 fifty]','','','',1); INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_common_score) values (32,630,'27','1 1/4','','','',1); INSERT INTO bike_wheel_sizes (TWMM, RDMM,RDIN,TWIN,RDFR,TWFR,DESCRIPTION,tire_common_score) values (40,635,'28','1 1/2 [1 3/8]','700 ','38B [35B]','',1); +COMMIT; diff --git a/db/seeds.rb b/db/seeds.rb index 60e7917..498311a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -18,10 +18,12 @@ if BikeBrand.all.empty? and BikeModel.all.empty? # so that the PG table ID sequence is incremented # # Note the drop(1) which assumes we have a junk PRAGMA line at the top - load_statements = File.readlines(File.join(Rails.root, 'db', 'seed', 'sql', 'bike_brands_and_models.sql')).drop(1).map do |statement| - statement.sub(/VALUES\(\d+,/, 'VALUES(DEFAULT,') + ['common_wheel_sizes.sql', 'bike_brands_and_models.sql'].each do |sql| + load_statements = File.readlines(File.join(Rails.root, 'db', 'seed', 'sql', sql)).drop(1).map do |statement| + statement.sub(/VALUES\(\d+,/, 'VALUES(DEFAULT,') + end + ActiveRecord::Base.connection.execute(load_statements.join) end - ActiveRecord::Base.connection.execute(load_statements.join) end if Rails.env.development?