Skip to content

Commit

Permalink
Fix db seed error
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasUCSB committed Dec 11, 2024
1 parent fd3f748 commit 406d018
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .ebextensions/01_install_dependencies.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ commands:
install_yarn:
command: |
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
yum install -y yarn
yum install -y yarn
seed_database:
command: |
cd /var/app/current && bundle exec rails db:seed RAILS_ENV=production
leader_only: true
24 changes: 14 additions & 10 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
require 'faker'

# Create a user to associate with the items
user = User.create(username: "test_seller", password: "test_seller")
user = User.find_or_create_by(username: "test_seller") do |u|
u.password = "test_seller"
end

# Generate 1000 items
1000.times do
Item.create(
user: user,
name: Faker::Commerce.product_name,
description: Faker::Lorem.sentence(word_count: 10),
price: Faker::Commerce.price(range: 1.0..100.0),
quantity: rand(1..100) # Random quantity between 1 and 100
)
# Generate items only if we don't have enough
if Item.count < 1000
(1000 - Item.count).times do
Item.create(
user: user,
name: Faker::Commerce.product_name,
description: Faker::Lorem.sentence(word_count: 10),
price: Faker::Commerce.price(range: 1.0..100.0),
quantity: rand(1..100)
)
end
end

0 comments on commit 406d018

Please sign in to comment.