Skip to content

Commit 59119ca

Browse files
committed
build: build with dependencies
1 parent d14dea3 commit 59119ca

File tree

10 files changed

+520
-61
lines changed

10 files changed

+520
-61
lines changed

.gitignore

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
2+
3+
.DS_Store
4+
.mise.*
5+
6+
deps.txt
7+
deps-ordered.txt
8+
19
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
210

3-
sql/000-version.sql
11+
src/version.sql
12+
13+
414

515
# Logs
616

@@ -186,7 +196,7 @@ cipherstash-proxy.toml
186196
# build artifacts
187197
release/
188198

189-
.mise.*
199+
190200

191201
# jupyter notebook
192202
.ipynb_checkpoints

mise.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
# "./tests/mise.tls.toml",
88
# ]
99
[task_config]
10-
includes = [
11-
"tasks",
12-
"tasks/postgres.toml"
13-
]
10+
includes = ["tasks", "tasks/postgres.toml"]
1411

1512
[env]
1613
POSTGRES_DB = "cipherstash"
1714
POSTGRES_USER = "cipherstash"
1815
POSTGRES_PASSWORD = "password"
1916
POSTGRES_HOST = "localhost"
2017
POSTGRES_PORT = "7432"
18+
19+
[tasks."clean"]
20+
alias = 'k'
21+
description = "Clean release"
22+
run = """
23+
rm -f release/cipherstash-encrypt-uninstall.sql
24+
rm -f release/cipherstash-encrypt.sql
25+
"""

tasks/build.sh

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,47 @@
77

88
#!/bin/bash
99

10-
set -euxo pipefail
10+
# set -euxo pipefail
1111

1212
mkdir -p release
1313

1414
rm -f release/cipherstash-encrypt-uninstall.sql
1515
rm -f release/cipherstash-encrypt.sql
1616

17-
rm -f sql/000-version.sql
17+
rm -f src/version.sql
18+
rm -f src/deps.txt
19+
rm -f src/deps-ordered.txt
1820

19-
RELEASE_VERSION=${usage_version}
20-
sed "s/\$RELEASE_VERSION/$RELEASE_VERSION/g" tasks/000-version-template.sql > sql/000-version.sql
2121

22+
RELEASE_VERSION=${usage_version:-DEV}
23+
sed "s/\$RELEASE_VERSION/$RELEASE_VERSION/g" src/version.template > src/version.sql
2224

23-
# Collect all the drops
24-
# In reverse order (tac) so that we drop the constraints before the tables
25-
grep -h -E '^(DROP)' sql/0*-*.sql | tac > release/cipherstash-encrypt-tmp-drop-install.sql
26-
# types are always last
27-
cat sql/666-drop_types.sql >> release/cipherstash-encrypt-tmp-drop-install.sql
2825

26+
find src -type f -path "*.sql" ! -path "*_test.sql" | while IFS= read -r sql_file; do
27+
echo $sql_file
2928

30-
# Build cipherstash-encrypt.sql
31-
# drop everything first
32-
cat sql/666-drop-operators.sql > release/cipherstash-encrypt.sql
33-
cat release/cipherstash-encrypt-tmp-drop-install.sql >> release/cipherstash-encrypt.sql
34-
# cat the rest of the sql files
35-
cat sql/0*-*.sql >> release/cipherstash-encrypt.sql
29+
echo "$sql_file $sql_file" >> src/deps.txt
3630

37-
# Collect all the drops
38-
# In reverse order (tac) so that we drop the constraints before the tables
39-
grep -h -E '^(DROP|ALTER DOMAIN [^ ]+ DROP CONSTRAINT)' sql/0*-*.sql | tac > release/cipherstash-encrypt-tmp-drop-uninstall.sql
40-
# types are always last
41-
cat sql/666-drop_types.sql >> release/cipherstash-encrypt-tmp-drop-uninstall.sql
31+
while IFS= read -r line; do
32+
# echo $line
33+
# Check if the line contains "-- REQUIRE:"
34+
if [[ "$line" == *"-- REQUIRE:"* ]]; then
35+
# Extract the required file(s) after "-- REQUIRE:"
36+
deps=${line#*-- REQUIRE: }
4237

38+
# Split multiple REQUIRE declarations if present
39+
for dep in $deps; do
40+
echo "$sql_file $dep" >> src/deps.txt
41+
done
42+
fi
43+
done < "$sql_file"
44+
done
4345

44-
# Build cipherstash-encrypt-uninstall.sql
45-
# prepend the drops to the main sql file
46-
cat sql/666-drop-operators.sql >> release/cipherstash-encrypt-uninstall.sql
47-
cat release/cipherstash-encrypt-tmp-drop-uninstall.sql >> release/cipherstash-encrypt-uninstall.sql
46+
cat src/deps.txt | tsort | tac > src/deps-ordered.txt
4847

48+
cat src/deps-ordered.txt | xargs cat | grep -v REQUIRE >> release/cipherstash-encrypt.sql
4949

50-
# uninstall renames configuration table
51-
cat sql/666-rename_configuration_table.sql >> release/cipherstash-encrypt-uninstall.sql
52-
53-
# remove the drop file
54-
rm release/cipherstash-encrypt-tmp-drop-install.sql
55-
rm release/cipherstash-encrypt-tmp-drop-uninstall.sql
50+
cat tasks/uninstall.sql >> release/cipherstash-encrypt-uninstall.sql
5651

5752
set +x
5853
echo

tasks/postgres.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ run = """
1010
{% set default_service = "postgres-" ~ get_env(name="POSTGRES_VERSION",default="17") %}
1111
echo docker compose up {{arg(name="service",default=default_service)}} {{option(name="extra-args",default="")}} | bash
1212
"""
13+
14+
["postgres:reset"]
15+
description = "Reset database"
16+
run = """
17+
mise run postgres:down
18+
mise run postgres:up --extra-args "--detach --wait"
19+
"""

tasks/reset.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,4 @@ fail_if_postgres_not_running
2727
cat release/cipherstash-encrypt-uninstall.sql | docker exec -i ${container_name} psql ${connection_url} -f-
2828

2929
# Wipe test data
30-
cat tests/999-wipe-test-data.sql | docker exec -i ${container_name} psql ${connection_url} -f-
31-
32-
# Install
33-
cat release/cipherstash-encrypt.sql | docker exec -i ${container_name} psql ${connection_url} -f-
30+
cat tasks/reset.sql | docker exec -i ${container_name} psql ${connection_url} -f-

tasks/reset.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- !!! Only used during tests !!
2+
-- Fully clean out the database between test runs
3+
4+
DROP SCHEMA public CASCADE;
5+
CREATE SCHEMA public;
6+
GRANT ALL ON SCHEMA public TO postgres;
7+
GRANT ALL ON SCHEMA public TO public;
8+
9+
DROP SCHEMA eql_v1 CASCADE;
10+
CREATE SCHEMA eql_v1;
11+
GRANT ALL ON SCHEMA eql_v1 TO postgres;
12+
GRANT ALL ON SCHEMA eql_v1 TO public;

tasks/test.sh

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
#MISE description="Build, reset and run tests"
3+
#USAGE flag "--test <test>" help="Test to run" default="false"
34
#USAGE flag "--postgres <version>" help="Run tests for specified Postgres version" default="17" {
45
#USAGE choices "14" "15" "16" "17"
56
#USAGE }
@@ -25,30 +26,53 @@ fail_if_postgres_not_running () {
2526
run_test () {
2627
echo
2728
echo '###############################################'
28-
echo "# ${1}"
29+
echo "# Running Test: ${1}"
2930
echo '###############################################'
3031
echo
31-
cat $1 | docker exec -i ${container_name} psql $connection_url -f-
32+
33+
34+
35+
cat $1 | docker exec -i ${container_name} psql --variable ON_ERROR_STOP=1 $connection_url -f-
36+
37+
3238
}
3339

3440
# setup
3541
fail_if_postgres_not_running
36-
mise run build
37-
mise run reset --postgres ${POSTGRES_VERSION}
38-
39-
# tests
40-
run_test tests/version.sql
41-
run_test tests/core.sql
42-
run_test tests/core-functions.sql
43-
run_test tests/config.sql
44-
run_test tests/encryptindex.sql
45-
run_test tests/operators-eq.sql
46-
run_test tests/operators-match.sql
47-
run_test tests/operators-ore.sql
48-
run_test tests/aggregate-ore.sql
49-
50-
echo
51-
echo '###############################################'
52-
echo "# ✅ALL TESTS PASSED "
53-
echo '###############################################'
54-
echo
42+
mise run build --force
43+
mise run reset --force --postgres ${POSTGRES_VERSION}
44+
45+
cat release/cipherstash-encrypt.sql
46+
47+
# Install
48+
# cat release/cipherstash-encrypt.sql | docker exec -i ${container_name} psql ${connection_url} -f-
49+
if cat release/cipherstash-encrypt.sql | docker exec -i ${container_name} psql ${connection_url} -f- | grep -q "ERROR"; then
50+
echo
51+
echo '***********************************************'
52+
echo 'ERROR installing release/cipherstash-encrypt.sql'
53+
echo '***********************************************'
54+
echo
55+
56+
exit 1
57+
fi
58+
59+
60+
cat tests/test_helpers.sql | docker exec -i ${container_name} psql ${connection_url} -f-
61+
cat tests/ore.sql | docker exec -i ${container_name} psql ${connection_url} -f-
62+
63+
if [ $usage_test = "false" ]; then
64+
find src -type f -path "*_test.sql" | while read -r sql_file; do
65+
echo $sql_file
66+
run_test $sql_file
67+
done
68+
else
69+
find src -type f -path "*$usage_test*" | while read -r sql_file; do
70+
run_test $sql_file
71+
done
72+
fi
73+
74+
# echo
75+
# echo '###############################################'
76+
# echo "# ✅ALL TESTS PASSED "
77+
# echo '###############################################'
78+
# echo

tasks/uninstall.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
DO $$
3+
BEGIN
4+
EXECUTE format('ALTER TABLE IF EXISTS %I RENAME TO %I_%s', 'eql_v1_configuration','eql_v1_configuration_', to_char(current_date,'YYYYMMDD')::TEXT);
5+
END
6+
$$;
7+
8+
DROP SCHEMA IF EXISTS eql_v1 CASCADE;

0 commit comments

Comments
 (0)