Skip to content

Commit

Permalink
fix db seed
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Sep 20, 2023
1 parent 7eb68f7 commit cfb6ad5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 52 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,8 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
Expand Down Expand Up @@ -1676,6 +1678,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.6.4-arm64-darwin)
sqlite3 (1.6.4-x86_64-linux)
stimulus-rails (1.2.2)
railties (>= 6.0.0)
Expand Down Expand Up @@ -1714,6 +1717,7 @@ GEM
zeitwerk (2.6.11)

PLATFORMS
arm64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
86 changes: 34 additions & 52 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
# db/seeds.rb

# Clear old data
puts "Cleaning up old data"
Card.destroy_all
KanbanColumn.destroy_all
Kanban.destroy_all
User.destroy_all # Remove this line if you don't want to reset the User
ActiveRecord::Base.transaction do
# Create default user
puts "Creating or finding user"
default_user = User.find_or_create_by!(email: '[email protected]') do |user|
user.password = 'Password01'
user.password_confirmation = 'Password01'
user.username = 'loftwah'
user.first_name = 'Dean'
user.last_name = 'Lofts'
user.short_description = 'DevOps Engineer, Proompter and a big fan of Open Source.'
user.tags = 'AWS,DevOps,GitHub,Open Source,Ruby,Ruby on Rails'
end

# Create default user
puts "Creating user"
default_user = User.create!(
email: '[email protected]',
password: 'Password01',
password_confirmation: 'Password01',
username: 'loftwah',
first_name: 'Dean',
last_name: 'Lofts',
short_description: 'DevOps Engineer, Proompter and a big fan of Open Source.',
tags: 'AWS,DevOps,GitHub,Open Source,Ruby,Ruby on Rails'
)
# Create Kanban Board
puts "Creating or finding demo Kanban Board"
demo_kanban = Kanban.find_or_create_by!(name: 'Linkarooie Project', user_id: default_user.id) do |kanban|
kanban.description = 'This is a demo board for Linkarooie application.'
end

# Create Kanban Board
puts "Creating demo Kanban Board"
demo_kanban = Kanban.create!(
name: 'Linkarooie Project',
description: 'This is a demo board for Linkarooie application.',
user_id: default_user.id
)
# Create Kanban Columns and Cards
puts "Creating or updating Kanban Columns and Cards"
['Backlog', 'In Progress', 'Completed'].each do |col_name|
column = demo_kanban.kanban_columns.find_or_create_by!(name: col_name)

# Create Kanban Columns and Cards
puts "Creating Kanban Columns and Cards"
['Backlog', 'In Progress', 'Completed'].each do |col_name|
column = demo_kanban.kanban_columns.create!(name: col_name)

case col_name
when 'Backlog'
tasks = [
'Set up the initial Rails project',
'Create Models and Migrations',
'Install Devise for User Authentication'
]
when 'In Progress'
tasks = [
'Develop CRUD operations for Links',
'Implement AWS S3 Storage'
]
when 'Completed'
tasks = [
'Initial Project Setup',
'Setup GitHub Actions for CI/CD'
]
end
tasks = case col_name
when 'Backlog'
['Set up the initial Rails project', 'Create Models and Migrations', 'Install Devise for User Authentication']
when 'In Progress'
['Develop CRUD operations for Links', 'Implement AWS S3 Storage']
when 'Completed'
['Initial Project Setup', 'Setup GitHub Actions for CI/CD']
end

tasks.each_with_index do |task, index|
column.cards.create!(content: task)
tasks.each_with_index do |task, _index|
column.cards.find_or_create_by!(content: task)
end
end
end

puts "Seeding complete."
puts "Seeding complete."
end

0 comments on commit cfb6ad5

Please sign in to comment.