|
| 1 | +name: Test PostgreSQL Versions |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, main ] |
| 6 | + pull_request: |
| 7 | + branches: [ master, main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + postgres-version: ['13', '14', '15', '16', '17', '18'] |
| 16 | + fail-fast: false |
| 17 | + |
| 18 | + services: |
| 19 | + postgres: |
| 20 | + image: postgres:${{ matrix.postgres-version }} |
| 21 | + env: |
| 22 | + POSTGRES_PASSWORD: postgres |
| 23 | + POSTGRES_DB: test |
| 24 | + POSTGRES_HOST_AUTH_METHOD: trust |
| 25 | + POSTGRES_INITDB_ARGS: --auth-host=trust --auth-local=trust |
| 26 | + options: >- |
| 27 | + --health-cmd pg_isready |
| 28 | + --health-interval 10s |
| 29 | + --health-timeout 5s |
| 30 | + --health-retries 5 |
| 31 | + ports: |
| 32 | + - 5432:5432 |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout code |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Install PostgreSQL client |
| 39 | + run: | |
| 40 | + # Install default PostgreSQL client (works for all versions) |
| 41 | + sudo apt-get update |
| 42 | + sudo apt-get install -y postgresql-client |
| 43 | + |
| 44 | + # Verify installation |
| 45 | + psql --version |
| 46 | + |
| 47 | + - name: Prepare test database |
| 48 | + run: | |
| 49 | + # Wait for PostgreSQL to be ready |
| 50 | + until pg_isready -h localhost -p 5432 -U postgres; do |
| 51 | + echo "Waiting for postgres..." |
| 52 | + sleep 2 |
| 53 | + done |
| 54 | + |
| 55 | + # Check PostgreSQL version |
| 56 | + psql -h localhost -U postgres -d test -c 'SELECT version();' |
| 57 | + |
| 58 | + # Create extensions (pg_stat_statements may not work without shared_preload_libraries) |
| 59 | + psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements;' || echo "Warning: pg_stat_statements extension not available" |
| 60 | + psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pgstattuple;' |
| 61 | + |
| 62 | + # Create minimal privilege user for testing |
| 63 | + psql -h localhost -U postgres -d test -c "CREATE USER dba_user;" |
| 64 | + psql -h localhost -U postgres -d test -c "GRANT pg_monitor TO dba_user;" |
| 65 | + psql -h localhost -U postgres -d test -c "GRANT CONNECT ON DATABASE test TO dba_user;" |
| 66 | + psql -h localhost -U postgres -d test -c "GRANT USAGE ON SCHEMA public TO dba_user;" |
| 67 | + |
| 68 | + # Verify extensions |
| 69 | + psql -h localhost -U postgres -d test -c 'SELECT extname FROM pg_extension ORDER BY extname;' |
| 70 | + |
| 71 | + # Create test tables for alignment testing (as superuser) |
| 72 | + psql -h localhost -U postgres -d test -c "CREATE TABLE align1 AS SELECT 1::int4, 2::int8, 3::int4 AS more FROM generate_series(1, 100000) _(i);" |
| 73 | + psql -h localhost -U postgres -d test -c "CREATE TABLE align2 AS SELECT 1::int4, 3::int4 AS more, 2::int8 FROM generate_series(1, 100000) _(i);" |
| 74 | + |
| 75 | + # Grant access to test tables for dba_user |
| 76 | + psql -h localhost -U postgres -d test -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO dba_user;" |
| 77 | + |
| 78 | + # Test connection as dba_user |
| 79 | + psql -h localhost -U dba_user -d test -c 'SELECT current_user, session_user;' |
| 80 | + |
| 81 | + - name: Test wide mode |
| 82 | + run: | |
| 83 | + echo "\set postgres_dba_wide true" > ~/.psqlrc |
| 84 | + echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc |
| 85 | + echo "Testing all SQL files in wide mode with minimal privileges..." |
| 86 | + for f in sql/*; do |
| 87 | + echo " Testing $f..." |
| 88 | + if ! psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then |
| 89 | + echo "❌ FAILED: $f in wide mode" |
| 90 | + echo "Error output:" |
| 91 | + psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | + done |
| 95 | + echo "✅ All tests passed in wide mode" |
| 96 | + |
| 97 | + - name: Test normal mode |
| 98 | + run: | |
| 99 | + echo "\set postgres_dba_wide false" > ~/.psqlrc |
| 100 | + echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc |
| 101 | + echo "Testing all SQL files in normal mode with minimal privileges..." |
| 102 | + for f in sql/*; do |
| 103 | + echo " Testing $f..." |
| 104 | + if ! psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then |
| 105 | + echo "❌ FAILED: $f in normal mode" |
| 106 | + echo "Error output:" |
| 107 | + psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + done |
| 111 | + echo "✅ All tests passed in normal mode" |
| 112 | + |
| 113 | + - name: Run regression tests |
| 114 | + run: | |
| 115 | + echo "\set postgres_dba_wide false" > ~/.psqlrc |
| 116 | + echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc |
| 117 | + |
| 118 | + echo "Running regression tests with minimal privileges..." |
| 119 | + |
| 120 | + echo " Testing 0_node.sql..." |
| 121 | + OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/0_node.sql | grep Role) |
| 122 | + if [[ "$OUTPUT" == *"Master"* ]]; then |
| 123 | + echo " ✓ Role test passed" |
| 124 | + else |
| 125 | + echo " ✗ Role test failed: $OUTPUT" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | + |
| 129 | + echo " Testing p1_alignment_padding.sql..." |
| 130 | + OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/p1_alignment_padding.sql | grep align) |
| 131 | + if [[ "$OUTPUT" == *"align1"* && "$OUTPUT" == *"align2"* && "$OUTPUT" == *"int4, more, int8"* ]]; then |
| 132 | + echo " ✓ Alignment padding test passed" |
| 133 | + else |
| 134 | + echo " ✗ Alignment padding test failed: $OUTPUT" |
| 135 | + exit 1 |
| 136 | + fi |
| 137 | + |
| 138 | + echo " Testing a1_activity.sql..." |
| 139 | + OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/a1_activity.sql | grep User) |
| 140 | + if [[ "$OUTPUT" == *"User"* ]]; then |
| 141 | + echo " ✓ Activity test passed" |
| 142 | + else |
| 143 | + echo " ✗ Activity test failed: $OUTPUT" |
| 144 | + exit 1 |
| 145 | + fi |
| 146 | + |
| 147 | + echo "✅ All regression tests passed with minimal privileges" |
| 148 | +
|
| 149 | +
|
0 commit comments