Skip to content

Commit 8a4dd1f

Browse files
committed
chore: cleanup of test and dbmage migration tool
1 parent b3bf99a commit 8a4dd1f

File tree

4 files changed

+18
-96
lines changed

4 files changed

+18
-96
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -72,87 +72,6 @@ jobs:
7272
echo "$ARGS" >> $GITHUB_OUTPUT
7373
echo "EOF" >> $GITHUB_OUTPUT
7474
75-
- run: docker context create builders
76-
- uses: docker/setup-buildx-action@v3
77-
with:
78-
endpoint: builders
79-
- uses: docker/build-push-action@v5
80-
with:
81-
load: true
82-
context: .
83-
file: Dockerfile-${{ env.PGMAJOR }}
84-
target: production
85-
build-args: |
86-
${{ steps.args.outputs.result }}
87-
tags: supabase/postgres:${{ steps.settings.outputs.postgres-version }},supabase_postgres
88-
cache-from: |
89-
type=gha,scope=${{ github.ref_name }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
90-
type=gha,scope=${{ github.base_ref }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
91-
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
92-
93-
- name: Start Postgres
94-
run: |
95-
docker run --rm --pull=never \
96-
-e POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }} \
97-
-p ${{ env.POSTGRES_PORT }}:5432 \
98-
--name supabase_postgres \
99-
-d supabase/postgres:${{ steps.settings.outputs.postgres-version }}
100-
101-
- name: Install psql
102-
run: |
103-
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
104-
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
105-
sudo apt update
106-
sudo apt install -y --no-install-recommends postgresql-client-${{ env.PGMAJOR }}
107-
108-
- name: Install pg_prove
109-
run: sudo cpan -T TAP::Parser::SourceHandler::pgTAP
110-
env:
111-
SHELL: /bin/bash
112-
113-
- name: Wait for healthy database
114-
run: |
115-
count=0
116-
until [ "$(docker inspect -f '{{.State.Health.Status}}' "$container")" == "healthy" ]; do
117-
exit=$?
118-
count=$((count + 1))
119-
if [ $count -ge "$retries" ]; then
120-
echo "Retry $count/$retries exited $exit, no more retries left."
121-
docker stop -t 2 "$container"
122-
return $exit
123-
fi
124-
sleep 1;
125-
done;
126-
echo "$container container is healthy"
127-
env:
128-
retries: 20
129-
container: supabase_postgres
130-
131-
- name: Run tests
132-
run: pg_prove migrations/tests/test.sql
133-
env:
134-
PGHOST: localhost
135-
PGPORT: ${{ env.POSTGRES_PORT }}
136-
PGDATABASE: postgres
137-
PGUSER: supabase_admin
138-
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
139-
140-
- name: Check migrations are idempotent
141-
run: |
142-
for sql in ./migrations/db/migrations/*.sql; do
143-
echo "$0: running $sql"
144-
psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -f "$sql"
145-
done
146-
env:
147-
PGHOST: localhost
148-
PGPORT: ${{ env.POSTGRES_PORT }}
149-
PGDATABASE: postgres
150-
PGUSER: supabase_admin
151-
PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
152-
153-
- name: Update Dockerfile.dbmate version
154-
run: |
155-
sed -i 's/%VERSION%/${{ env.PGMAJOR }}/g' migrations/Dockerfile.dbmate
15675
#TODO PR Convert to develop branch flakeurl
15776
- name: verify schema.sql is committed
15877
run: |

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,11 @@
678678
start-server = mkApp "start-server" "start-postgres-server";
679679
start-client = mkApp "start-client" "start-postgres-client";
680680
start-replica = mkApp "start-replica" "start-postgres-replica";
681-
migration-test = mkApp "migrate-tool" "migrate-postgres";
681+
migrate-postgres = mkApp "migrate-tool" "migrate-postgres";
682682
sync-exts-versions = mkApp "sync-exts-versions" "sync-exts-versions";
683683
pg-restore = mkApp "pg-restore" "pg-restore";
684684
dbmate-tool = mkApp "dbmate-tool" "dbmate-tool";
685+
migration-unit-tests = mkApp "migration-unit-tests" "migration-unit-tests";
685686
};
686687

687688
# 'devShells.default' lists the set of packages that are included in the

nix/tools/dbmate-tool.sh.in

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
PSQL_VERSION="ALL"
88
MIGRATION_FILE=""
99
PORTNO="@PGSQL_DEFAULT_PORT@"
10-
PGSQL_SUPERUSER=@PGSQL_SUPERUSER@
10+
PGSQL_SUPERUSER="@PGSQL_SUPERUSER@"
1111
PGPASSWORD="${PGPASSWORD:-postgres}"
1212
PGSQL_USER="postgres"
1313
FLAKE_URL="github:supabase/postgres"
1414
MIGRATIONS_DIR="@MIGRATIONS_DIR@"
15-
CURRENT_SYSTEM=@CURRENT_SYSTEM@
16-
ANSIBLE_VARS=@ANSIBLE_VARS@
15+
CURRENT_SYSTEM="@CURRENT_SYSTEM@"
16+
ANSIBLE_VARS="@ANSIBLE_VARS@"
1717
# Cleanup function
1818
cleanup() {
1919
echo "Cleaning up..."
@@ -174,8 +174,9 @@ EOF
174174
done
175175
}
176176
migrate_version() {
177+
echo "PSQL_VERSION: $PSQL_VERSION"
177178
overmind kill || true
178-
rm -f .overmind.sock Procfile || true
179+
rm -f .overmind.sock Procfile || true
179180
PSQLBIN=$(nix build --no-link "$FLAKE_URL#psql_$PSQL_VERSION/bin" --json | jq -r '.[].outputs.out + "/bin"')
180181
echo "Using PostgreSQL version $PSQL_VERSION from $PSQLBIN"
181182

@@ -243,6 +244,14 @@ EOSQL
243244

244245
# If we get here, all commands succeeded
245246
echo "PostgreSQL migration completed successfully"
247+
echo "Check migrations are idempotent"
248+
for sql in ./migrations/db/migrations/*.sql; do
249+
echo "$0: running $sql"
250+
"${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -f "$sql" || {
251+
echo "Failed to execute $sql"
252+
exit 1
253+
}
254+
done
246255
}
247256

248257
if [ "$PSQL_VERSION" == "all" ]; then

nix/tools/run-server.sh.in

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
# shellcheck shell=bash
33
[ ! -z "$DEBUG" ] && set -x
44
# first argument should be '15' or '16' for the version
5-
cleanup() {
6-
echo "Cleaning up temporary directory $DATDIR"
7-
if [ -d "$DATDIR" ]; then
8-
# Change permissions to allow removal
9-
chmod -R 700 "$DATDIR" 2>/dev/null || true
10-
rm -rf "$DATDIR" 2>/dev/null || sudo rm -rf "$DATDIR"
11-
fi
12-
}
13-
trap cleanup EXIT
145
if [ "$1" == "15" ]; then
156
echo "Starting server for PSQL 15"
167
PSQL15=@PSQL15_BINDIR@
@@ -47,7 +38,6 @@ export LANGUAGE=en_US.UTF-8
4738
export LC_ALL=en_US.UTF-8
4839
export LANG=en_US.UTF-8
4940
export LC_CTYPE=en_US.UTF-8
50-
mkdir -p "$DATDIR"
5141
echo "NOTE: using port $PORTNO for server"
5242
echo "NOTE: using temporary directory $DATDIR for data, which will not be removed"
5343
echo "NOTE: you are free to re-use this data directory at will"
@@ -59,6 +49,9 @@ cp "$READREPL_CONFIG_FILE" "$DATDIR/read-replica.conf"
5949
cp -r "$EXTENSION_CUSTOM_SCRIPTS" "$DATDIR"
6050
sed "s|supautils.privileged_extensions_custom_scripts_path = '/etc/postgresql-custom/extension-custom-scripts'|supautils.privileged_extensions_custom_scripts_path = '$DATDIR/extension-custom-scripts'|" "$SUPAUTILS_CONFIG_FILE" > "$DATDIR/supautils.conf"
6151
sed -e "1i\\
52+
dynamic_shared_memory_type = mmap\\
53+
shared_buffers = '64MB'\\
54+
max_connections = 20\\
6255
include = '$DATDIR/supautils.conf'" \
6356
-e "\$a\\
6457
pgsodium.getkey_script = '$PGSODIUM_GETKEY_SCRIPT'" \

0 commit comments

Comments
 (0)