-
Notifications
You must be signed in to change notification settings - Fork 0
feat!: add dependencies to role creation process #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
3088123
f7d7dc9
f9d82ed
51916ea
d885cb5
1c1d6a5
53d3cd7
dc8d9d5
be28166
1ee32d3
2de512c
4c62228
146779d
3d0f92c
25f1a51
6ee1030
f180f40
035acf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/bin/bash | ||
| # Task 1: Apply Terraform Configuration | ||
|
|
||
| set -e | ||
|
|
||
| echo "==============================================" | ||
| echo "Applying Terraform Configuration" | ||
| echo "==============================================" | ||
| echo "" | ||
|
|
||
| cd /Users/weston/clients/masterpoint/terraform-postgres-config-dbs-users-roles/examples/llm_chat_app | ||
|
|
||
| tofu apply -auto-approve | ||
|
|
||
| echo "" | ||
| echo "==============================================" | ||
| echo "Terraform Apply Completed Successfully!" | ||
| echo "==============================================" | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create test objects for verification | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export PGHOST=localhost | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export PGPORT=5432 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export PGDATABASE=llm_service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "==============================================" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Creating Test Objects" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "==============================================" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PGUSER=role_service_migration PGPASSWORD=demo-password-migration psql <<'EOF' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create test table in app schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE IF NOT EXISTS app.test_users ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id SERIAL PRIMARY KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name TEXT NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO app.test_users (name) VALUES ('test') ON CONFLICT DO NOTHING; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create test view in app schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE OR REPLACE VIEW app.test_users_view AS SELECT * FROM app.test_users; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create test function in app schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE OR REPLACE FUNCTION app.test_func() RETURNS integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LANGUAGE sql SECURITY INVOKER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AS $$ SELECT 1; $$; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create test table in ref_data schemas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE IF NOT EXISTS ref_data_pipeline_abc.test_ref ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id SERIAL PRIMARY KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value TEXT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO ref_data_pipeline_abc.test_ref (value) VALUES ('abc') ON CONFLICT DO NOTHING; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE IF NOT EXISTS ref_data_pipeline_xyz.test_ref ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id SERIAL PRIMARY KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value TEXT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO ref_data_pipeline_xyz.test_ref (value) VALUES ('xyz') ON CONFLICT DO NOTHING; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Create views in ref_data schemas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE OR REPLACE VIEW ref_data_pipeline_abc.test_ref_view AS SELECT * FROM ref_data_pipeline_abc.test_ref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE OR REPLACE VIEW ref_data_pipeline_xyz.test_ref_view AS SELECT * FROM ref_data_pipeline_xyz.test_ref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT 'Test objects created successfully!' AS result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n examples/llm_chat_app/2_create_test_objects.shRepository: masterpointio/terraform-postgres-config-dbs-users-roles Length of output: 2381 🌐 Web query:
💡 Result:
Behavior
Exit codes (what
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -e | |
| export PGHOST=localhost | |
| export PGPORT=5432 | |
| export PGDATABASE=llm_service | |
| echo "==============================================" | |
| echo "Creating Test Objects" | |
| echo "==============================================" | |
| echo "" | |
| PGUSER=service_migrator PGPASSWORD=demo-password-migrator psql <<'EOF' | |
| -- Switch to group role so objects are owned by role_service_migration | |
| -- This ensures default privileges apply correctly | |
| SET ROLE role_service_migration; | |
| -- Create test table in app schema | |
| CREATE TABLE IF NOT EXISTS app.test_users ( | |
| id SERIAL PRIMARY KEY, | |
| name TEXT NOT NULL | |
| ); | |
| INSERT INTO app.test_users (name) VALUES ('test') ON CONFLICT DO NOTHING; | |
| -- Create test view in app schema | |
| CREATE OR REPLACE VIEW app.test_users_view AS SELECT * FROM app.test_users; | |
| -- Create test function in app schema | |
| CREATE OR REPLACE FUNCTION app.test_func() RETURNS integer | |
| LANGUAGE sql SECURITY INVOKER | |
| AS $$ SELECT 1; $$; | |
| -- Create test table in ref_data schemas | |
| CREATE TABLE IF NOT EXISTS ref_data_pipeline_abc.test_ref ( | |
| id SERIAL PRIMARY KEY, | |
| value TEXT | |
| ); | |
| INSERT INTO ref_data_pipeline_abc.test_ref (value) VALUES ('abc') ON CONFLICT DO NOTHING; | |
| CREATE TABLE IF NOT EXISTS ref_data_pipeline_xyz.test_ref ( | |
| id SERIAL PRIMARY KEY, | |
| value TEXT | |
| ); | |
| INSERT INTO ref_data_pipeline_xyz.test_ref (value) VALUES ('xyz') ON CONFLICT DO NOTHING; | |
| -- Create views in ref_data schemas | |
| CREATE OR REPLACE VIEW ref_data_pipeline_abc.test_ref_view AS SELECT * FROM ref_data_pipeline_abc.test_ref; | |
| CREATE OR REPLACE VIEW ref_data_pipeline_xyz.test_ref_view AS SELECT * FROM ref_data_pipeline_xyz.test_ref; | |
| SELECT 'Test objects created successfully!' AS result; | |
| EOF | |
| set -e | |
| export PGHOST=localhost | |
| export PGPORT=5432 | |
| export PGDATABASE=llm_service | |
| echo "==============================================" | |
| echo "Creating Test Objects" | |
| echo "==============================================" | |
| echo "" | |
| PGUSER=service_migrator PGPASSWORD=demo-password-migrator psql -v ON_ERROR_STOP=1 <<'EOF' | |
| -- Switch to group role so objects are owned by role_service_migration | |
| -- This ensures default privileges apply correctly | |
| SET ROLE role_service_migration; | |
| -- Create test table in app schema | |
| CREATE TABLE IF NOT EXISTS app.test_users ( | |
| id SERIAL PRIMARY KEY, | |
| name TEXT NOT NULL | |
| ); | |
| INSERT INTO app.test_users (name) VALUES ('test') ON CONFLICT DO NOTHING; | |
| -- Create test view in app schema | |
| CREATE OR REPLACE VIEW app.test_users_view AS SELECT * FROM app.test_users; | |
| -- Create test function in app schema | |
| CREATE OR REPLACE FUNCTION app.test_func() RETURNS integer | |
| LANGUAGE sql SECURITY INVOKER | |
| AS $$ SELECT 1; $$; | |
| -- Create test table in ref_data schemas | |
| CREATE TABLE IF NOT EXISTS ref_data_pipeline_abc.test_ref ( | |
| id SERIAL PRIMARY KEY, | |
| value TEXT | |
| ); | |
| INSERT INTO ref_data_pipeline_abc.test_ref (value) VALUES ('abc') ON CONFLICT DO NOTHING; | |
| CREATE TABLE IF NOT EXISTS ref_data_pipeline_xyz.test_ref ( | |
| id SERIAL PRIMARY KEY, | |
| value TEXT | |
| ); | |
| INSERT INTO ref_data_pipeline_xyz.test_ref (value) VALUES ('xyz') ON CONFLICT DO NOTHING; | |
| -- Create views in ref_data schemas | |
| CREATE OR REPLACE VIEW ref_data_pipeline_abc.test_ref_view AS SELECT * FROM ref_data_pipeline_abc.test_ref; | |
| CREATE OR REPLACE VIEW ref_data_pipeline_xyz.test_ref_view AS SELECT * FROM ref_data_pipeline_xyz.test_ref; | |
| SELECT 'Test objects created successfully!' AS result; | |
| EOF |
🤖 Prompt for AI Agents
In `@examples/llm_chat_app/2_create_test_objects.sh` around lines 4 - 53, The psql
invocation that runs the here-doc (the line starting with
"PGUSER=service_migrator PGPASSWORD=demo-password-migrator psql <<'EOF'") does
not pass ON_ERROR_STOP, so SQL errors inside the here-doc can be ignored despite
set -e; update that psql command to include the flag -v ON_ERROR_STOP=1 so psql
exits non‑zero on the first SQL error and the script fails as expected.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/bin/bash | ||
| # Run all verification tests | ||
|
|
||
| set -e | ||
|
|
||
| export PGHOST=localhost | ||
| export PGPORT=5432 | ||
| export PGDATABASE=llm_service | ||
|
|
||
| echo "==============================================" | ||
| echo "Running Verification Tests" | ||
| echo "==============================================" | ||
| echo "" | ||
|
|
||
| # Test 2: Migration Role DDL Access | ||
| echo "--- Test 2: Migration Role DDL Access ---" | ||
| PGUSER=role_service_migration PGPASSWORD=demo-password-migration psql -c " | ||
| CREATE TABLE app.migration_test (id int); | ||
| ALTER TABLE app.migration_test ADD COLUMN name text; | ||
| DROP TABLE app.migration_test; | ||
| SELECT 'TEST 2 PASSED: Migration role has DDL access' AS result; | ||
| " | ||
| echo "" | ||
|
|
||
| # Test 3: FastAPI RW Role | ||
| echo "--- Test 3: FastAPI RW Role - DML on app schema ---" | ||
| PGUSER=role_service_fastapi_rw PGPASSWORD=demo-password-fastapi-rw psql -c " | ||
| SELECT * FROM app.test_users; | ||
| INSERT INTO app.test_users (name) VALUES ('fastapi_test'); | ||
| DELETE FROM app.test_users WHERE name = 'fastapi_test'; | ||
| SELECT 'TEST 3 PASSED: FastAPI RW has app DML' AS result; | ||
| " | ||
| echo "" | ||
|
|
||
| # Test 4: FastAPI RO Role | ||
| echo "--- Test 4: FastAPI RO Role - SELECT only ---" | ||
| PGUSER=role_service_fastapi_ro PGPASSWORD=demo-password-fastapi-ro psql -c " | ||
| SELECT * FROM app.test_users; | ||
| SELECT 'TEST 4 PASSED: FastAPI RO has SELECT' AS result; | ||
| " | ||
| echo "" | ||
|
|
||
| # Test 5: Pipeline RW Role | ||
| echo "--- Test 5: Pipeline RW Role - All schemas access ---" | ||
| PGUSER=role_service_pipeline_rw PGPASSWORD=demo-password-pipeline-rw psql -c " | ||
| SELECT * FROM app.test_users; | ||
| SELECT * FROM ref_data_pipeline_abc.test_ref; | ||
| SELECT * FROM ref_data_pipeline_xyz.test_ref; | ||
| SELECT 'TEST 5 PASSED: Pipeline RW has all schemas access' AS result; | ||
| " | ||
| echo "" | ||
|
|
||
| # Test 6: Pipeline RO Role | ||
| echo "--- Test 6: Pipeline RO Role - Read access to all schemas ---" | ||
| PGUSER=role_service_pipeline_ro PGPASSWORD=demo-password-pipeline-ro psql -c " | ||
| SELECT * FROM app.test_users; | ||
| SELECT * FROM ref_data_pipeline_abc.test_ref; | ||
| SELECT * FROM ref_data_pipeline_xyz.test_ref; | ||
| SELECT 'TEST 6 PASSED: Pipeline RO has SELECT on all schemas' AS result; | ||
| " | ||
| echo "" | ||
|
|
||
| # Test 7: Connection Limits | ||
| echo "--- Test 7: Connection Limits ---" | ||
| PGUSER=role_service_migration PGPASSWORD=demo-password-migration psql -c " | ||
| SELECT rolname, rolconnlimit | ||
| FROM pg_roles | ||
| WHERE rolname LIKE 'role_service_%' | ||
| ORDER BY rolname; | ||
| " | ||
| echo "" | ||
|
|
||
| # Test 8: Role Inheritance | ||
| echo "--- Test 8: Role Inheritance ---" | ||
| PGUSER=role_service_migration PGPASSWORD=demo-password-migration psql -c " | ||
| SELECT | ||
| r.rolname AS role, | ||
| ARRAY_AGG(m.rolname) AS member_of | ||
| FROM pg_roles r | ||
| LEFT JOIN pg_auth_members am ON r.oid = am.member | ||
| LEFT JOIN pg_roles m ON am.roleid = m.oid | ||
| WHERE r.rolname LIKE 'role_service_%' | ||
| GROUP BY r.rolname | ||
| ORDER BY r.rolname; | ||
| " | ||
| echo "" | ||
|
|
||
| echo "==============================================" | ||
| echo "All Tests Completed!" | ||
| echo "==============================================" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/bin/bash | ||
| # Cleanup: Delete all resources created by the example (but not admin_user) | ||
|
|
||
| set -e | ||
|
|
||
| export PGHOST=localhost | ||
| export PGPORT=5432 | ||
| export PGDATABASE=postgres # Connect to postgres db for cleanup | ||
|
|
||
| echo "==============================================" | ||
| echo "Cleaning Up Example Resources" | ||
| echo "==============================================" | ||
| echo "" | ||
|
|
||
| # Use admin_user to perform cleanup | ||
| export PGUSER=admin_user | ||
| export PGPASSWORD=insecure-pass-for-demo-admin-user | ||
|
|
||
| echo "Step 1: Terminating connections to llm_service database..." | ||
| psql -c " | ||
| SELECT pg_terminate_backend(pid) | ||
| FROM pg_stat_activity | ||
| WHERE datname = 'llm_service' AND pid <> pg_backend_pid(); | ||
| " 2>/dev/null || true | ||
|
|
||
| echo "" | ||
| echo "Step 2: Dropping database llm_service..." | ||
| psql -c "DROP DATABASE IF EXISTS llm_service;" | ||
|
|
||
| echo "" | ||
| echo "Step 3: Dropping login roles..." | ||
| # Drop login roles first (they depend on group roles) | ||
| psql <<'EOF' | ||
| DROP ROLE IF EXISTS role_service_migrator; | ||
| DROP ROLE IF EXISTS role_service_fastapi_rw; | ||
| DROP ROLE IF EXISTS role_service_fastapi_ro; | ||
| DROP ROLE IF EXISTS role_service_pipeline_rw; | ||
| DROP ROLE IF EXISTS role_service_pipeline_ro; | ||
| EOF | ||
|
|
||
| echo "" | ||
| echo "Step 4: Dropping group roles..." | ||
| # Drop group roles (no dependencies) | ||
| psql <<'EOF' | ||
| DROP ROLE IF EXISTS role_service_migration; | ||
| DROP ROLE IF EXISTS role_service_rw; | ||
| DROP ROLE IF EXISTS role_service_ro; | ||
| EOF | ||
|
|
||
| echo "" | ||
| echo "Step 5: Dropping cluster-wide roles..." | ||
| psql <<'EOF' | ||
| DROP ROLE IF EXISTS role_pg_cluster_admin; | ||
| DROP ROLE IF EXISTS role_pg_monitoring; | ||
| EOF | ||
|
|
||
| echo "" | ||
| echo "Step 6: Verifying cleanup..." | ||
| psql -c " | ||
| SELECT rolname FROM pg_roles | ||
| WHERE rolname LIKE 'role_service_%' OR rolname LIKE 'role_pg_%' | ||
| ORDER BY rolname; | ||
| " | ||
|
|
||
| echo "" | ||
| echo "==============================================" | ||
| echo "Cleanup Completed Successfully!" | ||
| echo "==============================================" | ||
| echo "" | ||
| echo "Note: admin_user was preserved." | ||
| echo "To re-run the example, start with: ./1_apply_terraform.sh" |
Uh oh!
There was an error while loading. Please reload this page.