Skip to content

Commit

Permalink
Merge pull request #26 from phuongngo0320/develop
Browse files Browse the repository at this point in the history
Remove image seed data
  • Loading branch information
pnv2003 authored Jul 25, 2024
2 parents ae18dd4 + e4eb87c commit 5100a29
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 90 deletions.
4 changes: 2 additions & 2 deletions bin/render-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -o errexit
bundle install
bundle exec rails assets:precompile
bundle exec rails assets:clean
# bundle exec rails db:migrate:reset # Add this line to reset the database
# bundle exec rails db:seed
bundle exec rails db:migrate:reset # Add this line to reset the database
bundle exec rails db:seed
176 changes: 88 additions & 88 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,106 +8,106 @@
# MovieGenre.find_or_create_by!(name: genre_name)
# end

def getfile(url)
stream = URI.open(url)
return stream if stream.respond_to?(:path)
# def getfile(url)
# stream = URI.open(url)
# return stream if stream.respond_to?(:path)

Tempfile.new.tap do |file|
file.binmode
IO.copy_stream(stream, file)
stream.close
file.rewind
end
end
# Tempfile.new.tap do |file|
# file.binmode
# IO.copy_stream(stream, file)
# stream.close
# file.rewind
# end
# end

# admin
User.create!(fname: "Phuong", lname: "Ngo", email: "pnv2003@gmail.com", password: "123", avatar: getfile(Faker::Avatar.image), admin: true, active: true, confirmed_at: Time.now)
User.create!(fname: "Phuong", lname: "Ngo", email: "phuongngovan2003@gmail.com", password: "123", admin: true, active: true, confirmed_at: Time.now)

puts "Done: admin"
# puts "Done: admin"

# known users
User.create!(fname: "Jameson", lname: "Kezzer", email: "jj@jj.jj", password: "jjj", avatar: getfile(Faker::Avatar.image), admin: false, active: true, confirmed_at: Time.now)
u = User.create!(fname: "Jackpot", lname: "Kattis", email: "kk@kk.kk", password: "kkk", avatar: getfile(Faker::Avatar.image), admin: false, active: true, confirmed_at: Time.now)
50.times do
desc = Faker::Quote.matz
post = u.posts.create!(
type: ['Photo', 'Album'].sample,
title: Faker::Company.name,
description: desc.length <= 300 ? desc : Faker::Lorem.paragraph_by_chars(number: Faker::Number.between(from: 1, to: 300)),
mode: ['public', 'private'].sample
)
# # known users
# User.create!(fname: "Jameson", lname: "Kezzer", email: "jj@jj.jj", password: "jjj", avatar: getfile(Faker::Avatar.image), admin: false, active: true, confirmed_at: Time.now)
# u = User.create!(fname: "Jackpot", lname: "Kattis", email: "kk@kk.kk", password: "kkk", avatar: getfile(Faker::Avatar.image), admin: false, active: true, confirmed_at: Time.now)
# 50.times do
# desc = Faker::Quote.matz
# post = u.posts.create!(
# type: ['Photo', 'Album'].sample,
# title: Faker::Company.name,
# description: desc.length <= 300 ? desc : Faker::Lorem.paragraph_by_chars(number: Faker::Number.between(from: 1, to: 300)),
# mode: ['public', 'private'].sample
# )

if post.type == "Photo"
post.medium = Medium.new(url: getfile(Faker::LoremFlickr.image))
else
Faker::Number.between(from: 1, to: 3).times do
post.media.new(url: getfile(Faker::LoremFlickr.image))
end
end
post.save
u.save
end
# if post.type == "Photo"
# post.medium = Medium.new(url: getfile(Faker::LoremFlickr.image))
# else
# Faker::Number.between(from: 1, to: 3).times do
# post.media.new(url: getfile(Faker::LoremFlickr.image))
# end
# end
# post.save
# u.save
# end

puts "Done: known users"
# puts "Done: known users"

# random users
Faker::Number.between(from: 20, to: 30).times do
user = User.create!(
fname: Faker::Name.first_name,
lname: Faker::Name.last_name,
email: Faker::Internet.email,
password: Faker::Internet.password,
admin: false,
active: [true, false].sample
)
# # random users
# Faker::Number.between(from: 20, to: 30).times do
# user = User.create!(
# fname: Faker::Name.first_name,
# lname: Faker::Name.last_name,
# email: Faker::Internet.email,
# password: Faker::Internet.password,
# admin: false,
# active: [true, false].sample
# )

Faker::Number.between(from: 1, to: 10).times do
desc = Faker::Quote.matz
post = user.posts.create!(
type: ['Photo', 'Album'].sample,
title: Faker::Company.name,
description: desc.length <= 300 ? desc : Faker::Lorem.paragraph_by_chars(number: Faker::Number.between(from: 1, to: 300)),
mode: ['public', 'private'].sample
)
# Faker::Number.between(from: 1, to: 10).times do
# desc = Faker::Quote.matz
# post = user.posts.create!(
# type: ['Photo', 'Album'].sample,
# title: Faker::Company.name,
# description: desc.length <= 300 ? desc : Faker::Lorem.paragraph_by_chars(number: Faker::Number.between(from: 1, to: 300)),
# mode: ['public', 'private'].sample
# )

if post.type == "Photo"
post.medium = Medium.new(url: getfile(Faker::LoremFlickr.image))
else
Faker::Number.between(from: 1, to: 3).times do
post.media.new(url: getfile(Faker::LoremFlickr.image))
end
end
post.save
end
end
# if post.type == "Photo"
# post.medium = Medium.new(url: getfile(Faker::LoremFlickr.image))
# else
# Faker::Number.between(from: 1, to: 3).times do
# post.media.new(url: getfile(Faker::LoremFlickr.image))
# end
# end
# post.save
# end
# end

puts "Done: random users"
# puts "Done: random users"

# random follows
user_ids = User.ids
user_pairs = user_ids.product(user_ids)
Faker::Number.between(from: 200, to: 500).times do
if user_pairs.empty?
break
end
user_id_1, user_id_2 = user_pairs.shuffle!.pop
if user_id_1 != user_id_2
Follow.create!(follower_id: user_id_1, followed_id: user_id_2)
end
end
# # random follows
# user_ids = User.ids
# user_pairs = user_ids.product(user_ids)
# Faker::Number.between(from: 200, to: 500).times do
# if user_pairs.empty?
# break
# end
# user_id_1, user_id_2 = user_pairs.shuffle!.pop
# if user_id_1 != user_id_2
# Follow.create!(follower_id: user_id_1, followed_id: user_id_2)
# end
# end

puts "Done: follows"
# puts "Done: follows"

# random reactions
user_ids = User.ids
post_ids = Post.ids
user_post_pairs = user_ids.product(post_ids)
Faker::Number.between(from: 200, to: 500).times do
if user_post_pairs.empty?
break
end
user_id, post_id = user_post_pairs.shuffle!.pop
Reaction.create!(user_id: user_id, post_id: post_id)
end
# # random reactions
# user_ids = User.ids
# post_ids = Post.ids
# user_post_pairs = user_ids.product(post_ids)
# Faker::Number.between(from: 200, to: 500).times do
# if user_post_pairs.empty?
# break
# end
# user_id, post_id = user_post_pairs.shuffle!.pop
# Reaction.create!(user_id: user_id, post_id: post_id)
# end

puts "Done: reactions"
# puts "Done: reactions"

0 comments on commit 5100a29

Please sign in to comment.