Skip to content
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

misc(docker): Improve migrate script #2778

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/tasks/signup.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@ namespace :signup do
task seed_organization: :environment do
if ENV['LAGO_CREATE_ORG'].present? && ENV['LAGO_CREATE_ORG'] == 'true'
pp 'starting seeding environment'
unless ENV['LAGO_ORG_USER_PASSWORD'].present? && ENV['LAGO_ORG_USER_EMAIL'].present? && ENV['LAGO_ORG_NAME'].present?
unless ENV['LAGO_ORG_USER_PASSWORD'].present? &&
ENV['LAGO_ORG_USER_EMAIL'].present? &&
ENV['LAGO_ORG_NAME'].present?
raise "Couldn't find LAGO_ORG_USER_PASSWORD, LAGO_ORG_USER_EMAIL or LAGO_ORG_NAME in environement variables"
end

user = User.create_with(password: ENV['LAGO_ORG_USER_PASSWORD'])
.find_or_create_by!(email: ENV['LAGO_ORG_USER_EMAIL'])
organization = Organization.find_or_create_by!(name: ENV['LAGO_ORG_NAME'])
raise "Couldn't find LAGO_ORG_API_KEY in environement variables" if ENV['LAGO_ORG_API_KEY'].blank?
organization.save!

existing_api_key = ApiKey.find_by(organization:, value: ENV['LAGO_ORG_API_KEY'])
Membership.find_or_create_by!(user:, organization:, role: :admin)

unless existing_api_key
api_key = ApiKey.create!(organization:)
api_key.update!(value: ENV['LAGO_ORG_API_KEY'])
if ENV['LAGO_ORG_API_KEY'].present?
api_key = ApiKey.find_or_create_by!(organization:, value: ENV['LAGO_API_KEY'])
api_key.update!(value: ENV['LAGO_API_KEY'])
else
ApiKey.find_or_create_by!(organization:)
end

Membership.find_or_create_by!(user:, organization:, role: :admin)

pp 'ending seeding environment'
end
end
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions scripts/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

if [ "$RAILS_ENV" == "staging" ]
then
bundle exec rake db:prepare
else
bundle exec rake db:create
bundle exec rails db:migrate

if [ -v LAGO_CREATE_ORG ] && [ "$LAGO_CREATE_ORG" == "true" ]
then
bundle exec rails signup:seed_organization
fi
fi
4 changes: 4 additions & 0 deletions scripts/start.api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

rm -f ./tmp/pids/server.pid
bundle exec rails s -b ::
4 changes: 0 additions & 4 deletions scripts/start.migrate.sh

This file was deleted.