From 1470aa0d04d6984de685317ad22c4c3956861db9 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:11:06 -0700 Subject: [PATCH 01/13] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0461784f02..7a0495dc3f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ pictrs/ # The generated typescript bindings bindings + +# Database cluster for testing +pgdata/ From 120b1b3999298eee542a816c1d01b544b5dac455 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:15:23 -0700 Subject: [PATCH 02/13] Create start-dev-db.sh --- scripts/start-dev-db.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 scripts/start-dev-db.sh diff --git a/scripts/start-dev-db.sh b/scripts/start-dev-db.sh new file mode 100644 index 0000000000..82e36cbdee --- /dev/null +++ b/scripts/start-dev-db.sh @@ -0,0 +1,5 @@ +# Run with `source` + +export PGDATA="$PWD/pgdata" + +initdb --username=lemmy --auth=trust From 16ae0b32692af3004c2d7f36e2a5b874d5c5a3f8 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:21:47 -0700 Subject: [PATCH 03/13] Rename start-dev-db.sh to start_dev_db.sh --- scripts/{start-dev-db.sh => start_dev_db.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{start-dev-db.sh => start_dev_db.sh} (100%) diff --git a/scripts/start-dev-db.sh b/scripts/start_dev_db.sh similarity index 100% rename from scripts/start-dev-db.sh rename to scripts/start_dev_db.sh From 91f42f5b36b3feb2d1e2cdd15c1a0d2e3c40c0c0 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:24:04 -0700 Subject: [PATCH 04/13] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7a0495dc3f..fce85a32cc 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,4 @@ pictrs/ bindings # Database cluster for testing -pgdata/ +dev_pgdata/ From 320d6e066bf905bd22b53f9aeb94a7cd39c7d5c5 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:24:49 -0700 Subject: [PATCH 05/13] Update start_dev_db.sh --- scripts/start_dev_db.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index 82e36cbdee..f4f7f7bc79 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -1,5 +1,6 @@ # Run with `source` -export PGDATA="$PWD/pgdata" +export PGDATA="$PWD/dev_pgdata" +rm -rf $PGDATA initdb --username=lemmy --auth=trust From ed57b8c9e6ff64f49a16d0b36ff3ea1f32011f15 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:46:41 -0700 Subject: [PATCH 06/13] Update start_dev_db.sh --- scripts/start_dev_db.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index f4f7f7bc79..0040e77296 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -4,3 +4,5 @@ export PGDATA="$PWD/dev_pgdata" rm -rf $PGDATA initdb --username=lemmy --auth=trust + +postgres -c listen-addresses='' From 6d8813ef1568ea012dd8aa5ae01e69a042a7927d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:51:23 -0700 Subject: [PATCH 07/13] Update start_dev_db.sh --- scripts/start_dev_db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index 0040e77296..88dee6c619 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -5,4 +5,4 @@ export PGDATA="$PWD/dev_pgdata" rm -rf $PGDATA initdb --username=lemmy --auth=trust -postgres -c listen-addresses='' +postgres -c listen_addresses='' -c "unix_socket_directories='$PWD'" From bf319d00704dc2834748dde18c10bc6e26d7a27c Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 12:54:00 -0700 Subject: [PATCH 08/13] Update start_dev_db.sh --- scripts/start_dev_db.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index 88dee6c619..b30ed84e5a 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -1,6 +1,7 @@ # Run with `source` export PGDATA="$PWD/dev_pgdata" +export LEMMY_DATABASE_URL="postgresql:///lemmy?host=$PWD" rm -rf $PGDATA initdb --username=lemmy --auth=trust From 99faeeb350665392b8e1d71d83d20c182c1cdc36 Mon Sep 17 00:00:00 2001 From: dull b Date: Tue, 27 Jun 2023 20:01:53 +0000 Subject: [PATCH 09/13] h --- .gitignore | 3 ++- scripts/start_dev_db.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fce85a32cc..e482488366 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,6 @@ pictrs/ # The generated typescript bindings bindings -# Database cluster for testing +# Database cluster and sockets for testing dev_pgdata/ +*.PGSQL.* diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index b30ed84e5a..9c73438a3b 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -6,4 +6,4 @@ export LEMMY_DATABASE_URL="postgresql:///lemmy?host=$PWD" rm -rf $PGDATA initdb --username=lemmy --auth=trust -postgres -c listen_addresses='' -c "unix_socket_directories='$PWD'" +postgres -c listen_addresses= -c unix_socket_directories=$PWD From 67f113728c4f00393c398249c3f8a78d8ace7cbf Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 13:17:38 -0700 Subject: [PATCH 10/13] Update test.sh --- scripts/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index f117238bd3..e947621492 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,10 +4,11 @@ set -e PACKAGE="$1" echo "$PACKAGE" +source scripts/start_dev_db.sh + psql -U lemmy -d postgres -c "DROP DATABASE lemmy;" psql -U lemmy -d postgres -c "CREATE DATABASE lemmy;" -export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy # tests are executed in working directory crates/api (or similar), # so to load the config we need to traverse to the repo root export LEMMY_CONFIG_LOCATION=../../config/config.hjson From 1f73f5701e983495038eb2f24c036b8ae42a045e Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 27 Jun 2023 13:31:57 -0700 Subject: [PATCH 11/13] Update start_dev_db.sh --- scripts/start_dev_db.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index 9c73438a3b..96236a59a7 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -7,3 +7,9 @@ rm -rf $PGDATA initdb --username=lemmy --auth=trust postgres -c listen_addresses= -c unix_socket_directories=$PWD + +# Wait for socket to exist +while test "$(echo *.PGSQL.*)" == '*.PGSQL.*' +do + sleep 0.1 +done From a32eda52985fe201594f3f0ba85cb5878ca90366 Mon Sep 17 00:00:00 2001 From: dull b Date: Wed, 28 Jun 2023 05:36:48 +0000 Subject: [PATCH 12/13] made it work --- scripts/start_dev_db.sh | 29 +++++++++++++++++++---------- scripts/test.sh | 6 +++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/scripts/start_dev_db.sh b/scripts/start_dev_db.sh index 96236a59a7..f192defa63 100644 --- a/scripts/start_dev_db.sh +++ b/scripts/start_dev_db.sh @@ -1,15 +1,24 @@ -# Run with `source` +# This script is meant to be run with `source` so it can set environment variables. export PGDATA="$PWD/dev_pgdata" -export LEMMY_DATABASE_URL="postgresql:///lemmy?host=$PWD" +export PGHOST=$PWD +export LEMMY_DATABASE_URL="postgresql://lemmy:password@/lemmy?host=$PWD" -rm -rf $PGDATA -initdb --username=lemmy --auth=trust +# If cluster exists, stop the server and delete the cluster +if [ -d $PGDATA ] +then + # Prevent `stop` from failing if server already stopped + pg_ctl restart > /dev/null + pg_ctl stop + rm -rf $PGDATA +fi -postgres -c listen_addresses= -c unix_socket_directories=$PWD +# Create cluster +initdb --username=postgres --auth=trust --no-instructions -# Wait for socket to exist -while test "$(echo *.PGSQL.*)" == '*.PGSQL.*' -do - sleep 0.1 -done +# Start server that only listens to socket in current directory +pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$PWD" > /dev/null + +# Setup database +psql -c "CREATE USER lemmy WITH PASSWORD 'password' SUPERUSER;" -U postgres +psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;" -U postgres diff --git a/scripts/test.sh b/scripts/test.sh index e947621492..6c747855fa 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -6,9 +6,6 @@ echo "$PACKAGE" source scripts/start_dev_db.sh -psql -U lemmy -d postgres -c "DROP DATABASE lemmy;" -psql -U lemmy -d postgres -c "CREATE DATABASE lemmy;" - # tests are executed in working directory crates/api (or similar), # so to load the config we need to traverse to the repo root export LEMMY_CONFIG_LOCATION=../../config/config.hjson @@ -22,3 +19,6 @@ else fi # Add this to do printlns: -- --nocapture + +pg_ctl stop +rm -rf $PGDATA From 97aed3e75df56539e3fc0a46a18ab2a2bbd8cf4b Mon Sep 17 00:00:00 2001 From: dull b Date: Wed, 28 Jun 2023 18:44:45 +0000 Subject: [PATCH 13/13] Make test.sh work when run from scripts dir --- scripts/test.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/test.sh b/scripts/test.sh index 6c747855fa..2a5efb30d1 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -e +CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" + +cd $CWD/../ + PACKAGE="$1" echo "$PACKAGE"