diff --git a/Gemfile.lock b/Gemfile.lock index 3c1f778..f3fcc92 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -1714,6 +1717,7 @@ GEM zeitwerk (2.6.11) PLATFORMS + arm64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/db/seeds.rb b/db/seeds.rb index 4c6393c..3d05651 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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: 'loftwah@linkarooie.com') 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: 'loftwah@linkarooie.com', - 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