Skip to content

Commit

Permalink
Enhanced release, many drops
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyhede committed Oct 28, 2024
1 parent f248461 commit dffd452
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 1,710 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/test-eql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Test EQL"
on:
push:
branches:
- main
paths:
- ".github/workflows/test-eql.yml"
- "sql/*.sql"

pull_request:
branches:
- main
paths:
- ".github/workflows/test-eql.yml"
- "sql/*.sql"

workflow_dispatch:

defaults:
run:
shell: bash -l {0}

jobs:
test:
name: "Test EQL SQL components"
runs-on: ubuntu-24.04

strategy:
fail-fast: false
matrix:
postgres-version: [17, 16, 15, 14]

env:
CS_DATABASE__PASSWORD:
CS_DATABASE__PORT: 5432
CS_DATABASE__NAME: test

steps:
- uses: actions/checkout@v4

- uses: extractions/setup-just@v1

- uses: ankane/setup-postgres@v1
with:
postgres-version: ${{ matrix.postgres-version }}
database: ${{ env.CS_DATABASE__NAME }}

- name: Test EQL
run: |
just build test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,5 @@ cipherstash-proxy.toml

# build artifacts
release/

.mise.*
55 changes: 43 additions & 12 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,71 @@ set dotenv-load
set positional-arguments


test_dsl:
test:
#!/usr/bin/env bash
set -euxo pipefail
PGPASSWORD=$CS_DATABASE__PASSWORD dropdb --force --if-exists --username $CS_DATABASE__USERNAME --port $CS_DATABASE__PORT cs_migrator_test
PGPASSWORD=$CS_DATABASE__PASSWORD createdb --username $CS_DATABASE__USERNAME --port $CS_DATABASE__PORT cs_migrator_test
PGPASSWORD=$CS_DATABASE__PASSWORD dropdb --force --if-exists --username ${CS_DATABASE__USERNAME:-$USER} --port $CS_DATABASE__PORT $CS_DATABASE__NAME
PGPASSWORD=$CS_DATABASE__PASSWORD createdb --username ${CS_DATABASE__USERNAME:-$USER} --port $CS_DATABASE__PORT $CS_DATABASE__NAME

connection_url=postgresql://$CS_DATABASE__USERNAME:@localhost:$CS_DATABASE__PORT/cs_migrator_test
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f sql/dsl-core.sql
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f sql/dsl-config-schema.sql
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f sql/dsl-config-functions.sql
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f sql/dsl-encryptindex.sql
connection_url=postgresql://${CS_DATABASE__USERNAME:-$USER}:@localhost:$CS_DATABASE__PORT/$CS_DATABASE__NAME

# Install
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f release/cipherstash-encrypt.sql

# tests
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f tests/core.sql
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f tests/config.sql
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f tests/encryptindex.sql

dropdb --username $CS_DATABASE__USERNAME --port $CS_DATABASE__PORT cs_migrator_test
# Uninstall
PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f release/cipherstash-encrypt-uninstall.sql

dropdb --username ${CS_DATABASE__USERNAME:-$USER} --port $CS_DATABASE__PORT $CS_DATABASE__NAME

build:
#!/usr/bin/env bash
set -euxo pipefail
mkdir -p release

cat sql/666-drop.sql > release/cipherstash-encrypt-uninstall.sql
grep -h '^DROP' sql/0*-*.sql | tac >> release/cipherstash-encrypt-uninstall.sql
rm -f release/cipherstash-encrypt-uninstall.sql
rm -f release/cipherstash-encrypt.sql

# Collect all the drops
# In reverse order (tac) so that we drop the constraints before the tables
grep -h -E '^(DROP|ALTER DOMAIN [^ ]+ DROP CONSTRAINT)' sql/0*-*.sql | tac > release/cipherstash-encrypt-tmp-drop.sql
# types are always last
cat sql/666-drop_types.sql >> release/cipherstash-encrypt-tmp-drop.sql


cat release/cipherstash-encrypt-uninstall.sql > release/cipherstash-encrypt.sql
# Build cipherstash-encrypt.sql
# drop everything first
cat release/cipherstash-encrypt-tmp-drop.sql > release/cipherstash-encrypt.sql
# cat the rest of the sql files
cat sql/0*-*.sql >> release/cipherstash-encrypt.sql


# Build cipherstash-encrypt-uninstall.sql
# prepend the drops to the main sql file
cat release/cipherstash-encrypt-tmp-drop.sql >> release/cipherstash-encrypt-uninstall.sql
# uninstall renames configuration table
cat sql/666-rename_configuration_table.sql >> release/cipherstash-encrypt-uninstall.sql

# remove the drop file
# rm release/cipherstash-encrypt-tmp-drop.sql


reset:
#!/usr/bin/env bash
set -euxo pipefail
PGPASSWORD=$CS_DATABASE__PASSWORD dropdb --force --if-exists --username ${CS_DATABASE__USERNAME:-$USER} --port $CS_DATABASE__PORT $CS_DATABASE__NAME
PGPASSWORD=$CS_DATABASE__PASSWORD createdb --username ${CS_DATABASE__USERNAME:-$USER} --port $CS_DATABASE__PORT $CS_DATABASE__NAME

PGPASSWORD=$CS_DATABASE__PASSWORD psql $connection_url -f release/cipherstash-encrypt.sql


psql:
psql postgresql://$CS_USERNAME:$CS_PASSWORD@localhost:$CS_PORT/$CS_DATABASE__NAME

Expand Down
Loading

0 comments on commit dffd452

Please sign in to comment.