From 7d8fbd193e61ce1b4e3f7069f5f45b0006b4734b Mon Sep 17 00:00:00 2001 From: kadewu Date: Thu, 10 Oct 2024 10:17:38 +0200 Subject: [PATCH 1/5] test temp --- run-automation.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 run-automation.sh diff --git a/run-automation.sh b/run-automation.sh new file mode 100755 index 000000000..42226d5ca --- /dev/null +++ b/run-automation.sh @@ -0,0 +1,11 @@ +#!/bin/bash +DIR="$( cd "$( dirname "$0" )" && pwd )" +SNAPSHOT=$DIR"/update-automation-snapshot.sql" +perl -pi -e 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT +# please note that you should not use this password on production services +DB_URL="postgresql://saleor:saleor@localhost:5432/" +FULL_DB_URL=$DB_URL"e2e" +psql $DB_URL -c 'DROP DATABASE IF EXISTS e2e;' +psql $DB_URL -c 'CREATE DATABASE e2e;' +psql $FULL_DB_URL -c 'CREATE EXTENSION IF NOT EXISTS btree_gin; CREATE EXTENSION IF NOT EXISTS pg_trgm;' +psql $FULL_DB_URL -f $SNAPSHOT From 75b8af6bfbfa3a642b8cdefb0b324c4007b99098 Mon Sep 17 00:00:00 2001 From: kadewu Date: Fri, 11 Oct 2024 12:51:45 +0200 Subject: [PATCH 2/5] force closing connections --- run-automation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-automation.sh b/run-automation.sh index 42226d5ca..67b0214d1 100755 --- a/run-automation.sh +++ b/run-automation.sh @@ -5,7 +5,7 @@ perl -pi -e 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHO # please note that you should not use this password on production services DB_URL="postgresql://saleor:saleor@localhost:5432/" FULL_DB_URL=$DB_URL"e2e" -psql $DB_URL -c 'DROP DATABASE IF EXISTS e2e;' +psql $DB_URL -c 'DROP DATABASE IF EXISTS e2e WITH(FORCE);' psql $DB_URL -c 'CREATE DATABASE e2e;' psql $FULL_DB_URL -c 'CREATE EXTENSION IF NOT EXISTS btree_gin; CREATE EXTENSION IF NOT EXISTS pg_trgm;' psql $FULL_DB_URL -f $SNAPSHOT From 238216cd94a600a17528cc71e182bf94e718e08a Mon Sep 17 00:00:00 2001 From: kadewu Date: Mon, 14 Oct 2024 20:52:44 +0200 Subject: [PATCH 3/5] use sed instead of perl for string replace --- run-automation.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run-automation.sh b/run-automation.sh index 67b0214d1..255bd6ed8 100755 --- a/run-automation.sh +++ b/run-automation.sh @@ -1,7 +1,9 @@ #!/bin/bash DIR="$( cd "$( dirname "$0" )" && pwd )" SNAPSHOT=$DIR"/update-automation-snapshot.sql" -perl -pi -e 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT +# perl -pi -e 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT +sed -i '' 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT +sed -i '' 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT # please note that you should not use this password on production services DB_URL="postgresql://saleor:saleor@localhost:5432/" FULL_DB_URL=$DB_URL"e2e" From 81f09a8ba1dc0700bd395af357e07bcb59191e5f Mon Sep 17 00:00:00 2001 From: kadewu Date: Tue, 15 Oct 2024 14:19:59 +0200 Subject: [PATCH 4/5] add running migration to the script --- run-automation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-automation.sh b/run-automation.sh index 255bd6ed8..dde9be2f2 100755 --- a/run-automation.sh +++ b/run-automation.sh @@ -1,7 +1,6 @@ #!/bin/bash DIR="$( cd "$( dirname "$0" )" && pwd )" SNAPSHOT=$DIR"/update-automation-snapshot.sql" -# perl -pi -e 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT sed -i '' 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT sed -i '' 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT # please note that you should not use this password on production services @@ -11,3 +10,4 @@ psql $DB_URL -c 'DROP DATABASE IF EXISTS e2e WITH(FORCE);' psql $DB_URL -c 'CREATE DATABASE e2e;' psql $FULL_DB_URL -c 'CREATE EXTENSION IF NOT EXISTS btree_gin; CREATE EXTENSION IF NOT EXISTS pg_trgm;' psql $FULL_DB_URL -f $SNAPSHOT +docker compose exec api python manage.py migrate From 9540ade3698a82f065088e47bf85d2dd7fae87de Mon Sep 17 00:00:00 2001 From: kadewu Date: Wed, 16 Oct 2024 19:59:47 +0200 Subject: [PATCH 5/5] review fixes: add comments and make script name more accurate --- run-automation.sh => setup-e2e-db.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) rename run-automation.sh => setup-e2e-db.sh (58%) diff --git a/run-automation.sh b/setup-e2e-db.sh similarity index 58% rename from run-automation.sh rename to setup-e2e-db.sh index dde9be2f2..ee98c76f9 100755 --- a/run-automation.sh +++ b/setup-e2e-db.sh @@ -1,13 +1,28 @@ #!/bin/bash +# Script to load update-automation-snapshot into our database (to public schema) +# It needs the docker compose from saleor platform repository: https://github.com/saleor/saleor-platform +# Tested only on MacOs + DIR="$( cd "$( dirname "$0" )" && pwd )" SNAPSHOT=$DIR"/update-automation-snapshot.sql" +# make sure to use `public` schema sed -i '' 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT sed -i '' 's/update_automation_snapshot_staging_saleor_cloud/public/' $SNAPSHOT + # please note that you should not use this password on production services DB_URL="postgresql://saleor:saleor@localhost:5432/" +# use different database for testing purpose FULL_DB_URL=$DB_URL"e2e" + +# drop previous database psql $DB_URL -c 'DROP DATABASE IF EXISTS e2e WITH(FORCE);' + +# create new database and make sure to install needed extensions psql $DB_URL -c 'CREATE DATABASE e2e;' psql $FULL_DB_URL -c 'CREATE EXTENSION IF NOT EXISTS btree_gin; CREATE EXTENSION IF NOT EXISTS pg_trgm;' + +# load the snapshot psql $FULL_DB_URL -f $SNAPSHOT + +# make sure to run migrations in case snapshot is not up to date with `core` migrations docker compose exec api python manage.py migrate