-
-
Save jyurek/c18149980e2e48baa96c072beaa08981 to your computer and use it in GitHub Desktop.
Insert lots of rows to test indices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
ingredients = %w[ | |
Ham | |
Water | |
Sodium\ Bicarbonate | |
Acetic\ Acid | |
Salt | |
Natural\ Flavors | |
Artificial\ Flavors | |
Onion | |
Milk | |
] | |
food_adjectives = %w[ | |
Awesome | |
Party\ Size | |
Bubbling | |
Groovy | |
Extreme | |
Cheese | |
New | |
Red | |
Mountain | |
Whole\ Grain | |
] | |
food_nouns = %w[ | |
Crisps | |
Ham | |
Ghosts | |
Popplers | |
Gummies | |
Dew | |
Salsa | |
Cheese | |
Deliciousness | |
Experiments | |
] | |
f = File.open('out.sql', 'w') | |
1_000_000.times do |i| | |
name = [food_adjectives.sample, food_adjectives.sample, food_nouns.sample] | |
.join(' ') | |
upc = format('%0.10i', rand(1_000_000_000)) | |
recipe = (0..(rand(5))) | |
.to_a | |
.map { { name: ingredients.sample, mg: (rand 1000) + 1 } } | |
.to_json | |
f.puts(<<-end_sql) | |
INSERT INTO foods (name, upc, ingredients) | |
VALUES ('#{name}', '#{upc}', '#{recipe}'); | |
end_sql | |
puts i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
ingredients = %w[ | |
Ham | |
Water | |
Sodium\ Bicarbonate | |
Acetic\ Acid | |
Salt | |
Natural\ Flavors | |
Artificial\ Flavors | |
Onion | |
Milk | |
] | |
food_adjectives = %w[ | |
Awesome | |
Party\ Size | |
Bubbling | |
Groovy | |
Extreme | |
Cheese | |
New | |
Red | |
Mountain | |
Whole\ Grain | |
] | |
food_nouns = %w[ | |
Crisps | |
Ham | |
Ghosts | |
Popplers | |
Gummies | |
Dew | |
Salsa | |
Cheese | |
Deliciousness | |
Experiments | |
] | |
f = File.open('out.sql', 'w') | |
1_000_000.times do |i| | |
name = [food_adjectives.sample, food_adjectives.sample, food_nouns.sample] | |
.join(' ') | |
upc = format('%0.10i', rand(1_000_000_000)) | |
recipe = (0..(rand(5))) | |
.to_a | |
.map { { name: ingredients.sample, mg: (rand 1000) + 1 } } | |
.map(&:to_json) | |
.map { |s| "'#{s}'" } | |
.join(',') | |
f.puts(<<-end_sql) | |
INSERT INTO foods (name, upc, ingredients) | |
VALUES ('#{name}', '#{upc}', ARRAY[#{recipe}]::jsonb[]); | |
end_sql | |
puts i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment