mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 08:55:36 -04:00 
			
		
		
		
	Merge pull request #71 from spacemunkay/sequence-increment-bug-31
Fixed the seeder loading the sql incorrectly; now stubs the index out so...
This commit is contained in:
		
						commit
						9a78478f1a
					
				| @ -162,7 +162,6 @@ GEM | ||||
|       rdoc (~> 3.4) | ||||
|       thor (>= 0.14.6, < 2.0) | ||||
|     rake (10.0.4) | ||||
|     rb-fsevent (0.9.3) | ||||
|     rdoc (3.12.2) | ||||
|       json (~> 1.4) | ||||
|     rspec (2.8.0) | ||||
| @ -242,7 +241,6 @@ DEPENDENCIES | ||||
|   pg | ||||
|   pry (~> 0.9.8) | ||||
|   rails (= 3.2.13) | ||||
|   rb-fsevent | ||||
|   rspec-rails (~> 2.8.1) | ||||
|   shoulda-matchers (~> 1.0.0) | ||||
|   spork | ||||
|  | ||||
							
								
								
									
										10
									
								
								db/seeds.rb
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								db/seeds.rb
									
									
									
									
									
								
							| @ -14,10 +14,12 @@ end | ||||
| 
 | ||||
| #Load bike brands and models from sql | ||||
| if BikeBrand.all.empty? and BikeModel.all.empty? | ||||
|   sql_path = File.join(Rails.root, 'db', 'seed', 'sql', 'bike_brands_and_models.sql') | ||||
|   db_config = Rails.application.config.database_configuration[Rails.env] | ||||
|   cmd = "psql #{db_config["database"]} < #{sql_path}" | ||||
|   system cmd | ||||
|   # Need to use DEFAULT instead of explicit IDs that are used in the sql file, | ||||
|   # so that the PG table ID sequence is incremented | ||||
|   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,').tap {|x| puts x } | ||||
|   end | ||||
|   ActiveRecord::Base.connection.execute(load_statements.join) | ||||
| end | ||||
| 
 | ||||
| if Rails.env.development? | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user