From 72930bad9f8989eed496a8ff36d624688f92a162 Mon Sep 17 00:00:00 2001 From: jdenquin Date: Tue, 5 Nov 2024 11:40:55 +0100 Subject: [PATCH 1/3] misc(docker): improve migrate script --- scripts/start.migrate.dev.sh | 4 ---- scripts/start.migrate.sh | 4 ---- 2 files changed, 8 deletions(-) delete mode 100755 scripts/start.migrate.dev.sh delete mode 100755 scripts/start.migrate.sh diff --git a/scripts/start.migrate.dev.sh b/scripts/start.migrate.dev.sh deleted file mode 100755 index 94ffc697e35..00000000000 --- a/scripts/start.migrate.dev.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -bundle install -bundle exec rails db:migrate diff --git a/scripts/start.migrate.sh b/scripts/start.migrate.sh deleted file mode 100755 index 94ffc697e35..00000000000 --- a/scripts/start.migrate.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -bundle install -bundle exec rails db:migrate From d7bf86400acbfcb3dc5f4504997807f77f6923ad Mon Sep 17 00:00:00 2001 From: jdenquin Date: Tue, 5 Nov 2024 12:24:05 +0100 Subject: [PATCH 2/3] improve signup rake task --- lib/tasks/signup.rake | 19 +++++++++---------- scripts/migrate.dev.sh | 4 ++++ scripts/migrate.sh | 14 ++++++++++++++ scripts/start.api.sh | 4 ++++ 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100755 scripts/migrate.dev.sh create mode 100755 scripts/migrate.sh create mode 100755 scripts/start.api.sh diff --git a/lib/tasks/signup.rake b/lib/tasks/signup.rake index 9bf0c4c3d52..f90041baee1 100644 --- a/lib/tasks/signup.rake +++ b/lib/tasks/signup.rake @@ -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 diff --git a/scripts/migrate.dev.sh b/scripts/migrate.dev.sh new file mode 100755 index 00000000000..94ffc697e35 --- /dev/null +++ b/scripts/migrate.dev.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +bundle install +bundle exec rails db:migrate diff --git a/scripts/migrate.sh b/scripts/migrate.sh new file mode 100755 index 00000000000..1c84b65c4c9 --- /dev/null +++ b/scripts/migrate.sh @@ -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 [ "$LAGO_CREATE_ORG" == "true" ] + then + bundle exec rails signup:seed_organization + fi +fi diff --git a/scripts/start.api.sh b/scripts/start.api.sh new file mode 100755 index 00000000000..df0938c16e5 --- /dev/null +++ b/scripts/start.api.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rm -f ./tmp/pids/server.pid +bundle exec rails s -b :: From 53374698a143654e6ddb274910bd2a844e53ba8a Mon Sep 17 00:00:00 2001 From: jdenquin Date: Tue, 5 Nov 2024 15:25:28 +0100 Subject: [PATCH 3/3] fix test for create org --- scripts/migrate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/migrate.sh b/scripts/migrate.sh index 1c84b65c4c9..ed4b20b13c4 100755 --- a/scripts/migrate.sh +++ b/scripts/migrate.sh @@ -7,7 +7,7 @@ else bundle exec rake db:create bundle exec rails db:migrate - if [ "$LAGO_CREATE_ORG" == "true" ] + if [ -v LAGO_CREATE_ORG ] && [ "$LAGO_CREATE_ORG" == "true" ] then bundle exec rails signup:seed_organization fi