-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move current seeds.rb
script to new DevStarter
module (lib/seed/seeder.rb
)
#767
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
29b4a7e
add new constants.rb file in lib/seed to help store all constants nee…
kolharsam 87d50a8
create new Seed module with DevStarter class to help run current step…
kolharsam 10410ca
update seeds.rb to use the new module from seed lib
kolharsam d444e69
update methods in DevStarter class in Seed module to be private
kolharsam 6caf530
update README
kolharsam ce3504d
fix lint changes
kolharsam 9892806
attempt to fix issue with test github job
kolharsam dd03e0d
Merge branch 'main' into sam-demo-env-1
kolharsam 93c1092
Merge branch 'main' into sam-demo-env-1
kolharsam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,3 @@ | ||
# rubocop:disable Rails/Output | ||
puts "Seeding database..." | ||
|
||
# Admin user | ||
# ---------- | ||
ADMIN_FULL_NAME = "Admin User" | ||
ADMIN_PREFERRED_NAME = "Admin" | ||
ADMIN_EMAIL = "admin@tramline.app" | ||
ADMIN_PASSWORD = "why aroma enclose startup" | ||
|
||
admin_user = lambda do | ||
email_authentication = Accounts::EmailAuthentication.find_or_initialize_by(email: ADMIN_EMAIL) | ||
admin = true | ||
|
||
unless email_authentication.persisted? | ||
user = Accounts::User.find_or_create_by!(full_name: ADMIN_FULL_NAME, preferred_name: ADMIN_PREFERRED_NAME, admin:, unique_authn_id: ADMIN_EMAIL) | ||
email_authentication.update!(password: ADMIN_PASSWORD, confirmed_at: DateTime.now, user:) | ||
end | ||
|
||
puts "Added/updated admin user." | ||
end | ||
|
||
# Owner user | ||
# -------------- | ||
OWNER_FULL_NAME = "Owner User" | ||
OWNER_PREFERRED_NAME = "Owner" | ||
OWNER_EMAIL = "owner@tramline.app" | ||
OWNER_PASSWORD = "why aroma enclose startup" | ||
|
||
owner_user = lambda do | ||
email_authentication = Accounts::EmailAuthentication.find_or_initialize_by(email: OWNER_EMAIL) | ||
|
||
if email_authentication.persisted? | ||
user = email_authentication.user | ||
else | ||
user = Accounts::User.find_or_create_by!(full_name: OWNER_FULL_NAME, preferred_name: OWNER_PREFERRED_NAME, unique_authn_id: OWNER_EMAIL) | ||
email_authentication.update!(password: OWNER_PASSWORD, confirmed_at: DateTime.now, user:) | ||
email_authentication.reload | ||
end | ||
|
||
organization = Accounts::Organization.find_or_create_by!( | ||
name: "Tramline Test 1 (Owner)", | ||
status: Accounts::Organization.statuses[:active], | ||
created_by: email_authentication.email | ||
) | ||
|
||
Accounts::Membership.find_or_create_by!( | ||
user:, | ||
organization:, | ||
role: Accounts::Membership.roles[:owner] | ||
) | ||
|
||
puts "Added/updated owner user." | ||
end | ||
|
||
# Developer user | ||
# -------------- | ||
DEVELOPER_FULL_NAME = "Developer User" | ||
DEVELOPER_PREFERRED_NAME = "Developer" | ||
DEVELOPER_EMAIL = "developer@tramline.app" | ||
DEVELOPER_PASSWORD = "why aroma enclose startup" | ||
|
||
developer_user = lambda do | ||
email_authentication = Accounts::EmailAuthentication.find_or_initialize_by(email: DEVELOPER_EMAIL) | ||
|
||
if email_authentication.persisted? | ||
user = email_authentication.user | ||
else | ||
user = Accounts::User.find_or_create_by!(full_name: DEVELOPER_FULL_NAME, preferred_name: DEVELOPER_PREFERRED_NAME, unique_authn_id: DEVELOPER_EMAIL) | ||
email_authentication.update!(password: DEVELOPER_PASSWORD, confirmed_at: DateTime.now, user:) | ||
email_authentication.reload | ||
end | ||
|
||
organization = Accounts::Organization.find_or_create_by!( | ||
name: "Tramline Test 1 (Developer)", | ||
status: Accounts::Organization.statuses[:active], | ||
created_by: email_authentication.email | ||
) | ||
|
||
Accounts::Membership.find_or_create_by!( | ||
user:, | ||
organization:, | ||
role: Accounts::Membership.roles[:developer] | ||
) | ||
|
||
puts "Added/updated developer user." | ||
end | ||
|
||
ActiveRecord::Base.transaction do | ||
admin_user.call | ||
owner_user.call | ||
developer_user.call | ||
end | ||
Seed::DevStarter.call | ||
# rubocop:enable Rails/Output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Seed | ||
module Constants | ||
# admin constants | ||
ADMIN_FULL_NAME = "Admin User" | ||
ADMIN_PREFERRED_NAME = "Admin" | ||
ADMIN_EMAIL = "admin@tramline.app" | ||
ADMIN_PASSWORD = "why aroma enclose startup" | ||
|
||
# owner constants | ||
OWNER_FULL_NAME = "Owner User" | ||
OWNER_PREFERRED_NAME = "Owner" | ||
OWNER_EMAIL = "owner@tramline.app" | ||
OWNER_PASSWORD = "why aroma enclose startup" | ||
|
||
# developer constants | ||
DEVELOPER_FULL_NAME = "Developer User" | ||
DEVELOPER_PREFERRED_NAME = "Developer" | ||
DEVELOPER_EMAIL = "developer@tramline.app" | ||
DEVELOPER_PASSWORD = "why aroma enclose startup" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# rubocop:disable Rails/Output | ||
|
||
module Seed | ||
class DevStarter | ||
include Seed::Constants | ||
|
||
def call | ||
puts "Seeding database..." | ||
|
||
ActiveRecord::Base.transaction do | ||
self.class.send(:create_admin_user) | ||
self.class.send(:create_owner_user) | ||
self.class.send(:create_developer_user) | ||
end | ||
|
||
puts "Completed seeding database" | ||
end | ||
|
||
def self.create_admin_user | ||
email_authentication = Accounts::EmailAuthentication.find_or_initialize_by(email: ADMIN_EMAIL) | ||
admin = true | ||
|
||
unless email_authentication.persisted? | ||
user = Accounts::User.find_or_create_by!(full_name: ADMIN_FULL_NAME, preferred_name: ADMIN_PREFERRED_NAME, admin:, unique_authn_id: ADMIN_EMAIL) | ||
email_authentication.update!(password: ADMIN_PASSWORD, confirmed_at: DateTime.now, user:) | ||
end | ||
|
||
puts "Added/updated admin user." | ||
end | ||
|
||
def self.create_owner_user | ||
email_authentication = Accounts::EmailAuthentication.find_or_initialize_by(email: OWNER_EMAIL) | ||
|
||
if email_authentication.persisted? | ||
user = email_authentication.user | ||
else | ||
user = Accounts::User.find_or_create_by!(full_name: OWNER_FULL_NAME, preferred_name: OWNER_PREFERRED_NAME, unique_authn_id: OWNER_EMAIL) | ||
email_authentication.update!(password: OWNER_PASSWORD, confirmed_at: DateTime.now, user:) | ||
email_authentication.reload | ||
end | ||
|
||
organization = Accounts::Organization.find_or_create_by!( | ||
name: "Tramline Test 1 (Owner)", | ||
status: Accounts::Organization.statuses[:active], | ||
created_by: email_authentication.email | ||
) | ||
|
||
Accounts::Membership.find_or_create_by!( | ||
user:, | ||
organization:, | ||
role: Accounts::Membership.roles[:owner] | ||
) | ||
|
||
puts "Added/updated owner user." | ||
end | ||
|
||
def self.create_developer_user | ||
email_authentication = Accounts::EmailAuthentication.find_or_initialize_by(email: DEVELOPER_EMAIL) | ||
|
||
if email_authentication.persisted? | ||
user = email_authentication.user | ||
else | ||
user = Accounts::User.find_or_create_by!(full_name: DEVELOPER_FULL_NAME, preferred_name: DEVELOPER_PREFERRED_NAME, unique_authn_id: DEVELOPER_EMAIL) | ||
email_authentication.update!(password: DEVELOPER_PASSWORD, confirmed_at: DateTime.now, user:) | ||
email_authentication.reload | ||
end | ||
|
||
organization = Accounts::Organization.find_or_create_by!( | ||
name: "Tramline Test 1 (Developer)", | ||
status: Accounts::Organization.statuses[:active], | ||
created_by: email_authentication.email | ||
) | ||
|
||
Accounts::Membership.find_or_create_by!( | ||
user:, | ||
organization:, | ||
role: Accounts::Membership.roles[:developer] | ||
) | ||
|
||
puts "Added/updated developer user." | ||
end | ||
|
||
private_class_method :create_admin_user | ||
private_class_method :create_owner_user | ||
private_class_method :create_developer_user | ||
end | ||
end | ||
|
||
# rubocop:enable Rails/Output |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue this needn't be called like this, we can just call it like
self.class.create_admin_user
and remove theprivate
. But better yet, since this class doesn't have state yet, the point of the class is sort of very low value. Classes encapsulate state. But it may in the future, so I would recommend just do something like:And make all those class methods, instance methods (and you can keep them private).