From d6ffc8dabf6572f2b32791735bb24e1f09a7c628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Wed, 9 Aug 2023 17:01:12 +0200 Subject: [PATCH] fix: seeds ## Description I'm getting into this project again and the first thing that pops up is that in `db/seeds.rb` the records are not persisted. ## How to test 1. `bin/rails db:drop db:create db:migrate db:seed` 2. Does not crash anymore --- db/schema.rb | 2 +- db/seeds.rb | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 69f58bd21..3e6fb9997 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -111,9 +111,9 @@ t.datetime "additional_consent_given_at" t.bigint "organization_id" t.string "whats_app_phone_number" + t.datetime "whats_app_message_template_responded_at" t.bigint "deactivated_by_user_id" t.boolean "deactivated_by_admin", default: false - t.datetime "whats_app_message_template_responded_at" t.datetime "whats_app_message_template_sent_at" t.index ["email"], name: "index_contributors_on_email", unique: true t.index ["organization_id"], name: "index_contributors_on_organization_id" diff --git a/db/seeds.rb b/db/seeds.rb index 57e6e24e4..265f7e6ed 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -4,13 +4,26 @@ password = ENV.fetch('SEED_USER_PASSWORD', SecureRandom.alphanumeric(20)) otp_secret_key = ENV.fetch('SEED_USER_OTP_SECRET', User.otp_random_secret) -organization = Organization.create_or_find_by(name: '100eyes', - upgrade_discount: 10, - business_plan: BusinessPlan.first) -admin = User.create_or_find_by(email: 'redaktion@tactile.news', first_name: 'Dennis', last_name: 'Schröder', password: password, - admin: true, otp_secret_key: otp_secret_key) -user = User.create_or_find_by(email: 'contact-person@example_organization.org', first_name: 'ConactFor', last_name: 'Organization', - password: password, otp_secret_key: otp_secret_key, organization: organization) +business_plan = BusinessPlan.create!( + name: 'Free', + price_per_month: 0, + setup_cost: 0, + hours_of_included_support: 0, + number_of_users: 5, + number_of_contributors: 150, + number_of_communities: 1, + valid_from: Time.current, + valid_until: Time.current + 6.months +) +organization = Organization.create_or_find_by!( + name: '100eyes', + upgrade_discount: 10, + business_plan: business_plan +) +admin = User.create_or_find_by!(email: 'redaktion@tactile.news', first_name: 'Dennis', last_name: 'Schröder', password: password, + admin: true, otp_secret_key: otp_secret_key) +user = User.create_or_find_by!(email: 'contact-person@example-organization.org', first_name: 'ConactFor', last_name: 'Organization', + password: password, otp_secret_key: otp_secret_key, organization: organization) organization.update(contact_person: user) puts "Organization with name #{organization.name}" puts "Admin with email #{admin.email}"