From e6ab249e5c4adc63e2f11fdcc77bf40ad317fe8d Mon Sep 17 00:00:00 2001 From: Peter Sirotnak Date: Wed, 28 May 2025 07:41:23 +0200 Subject: [PATCH 1/2] PMM-7: 3.2.0 Fixes --- pmm_qa/pdpgsql_pgsm_setup.yml | 18 ++++ .../percona_server/percona-server-setup.yml | 2 +- pmm_qa/scripts/pgsql_load.sql | 91 +++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 pmm_qa/scripts/pgsql_load.sql diff --git a/pmm_qa/pdpgsql_pgsm_setup.yml b/pmm_qa/pdpgsql_pgsm_setup.yml index 09bb4dcb..a2742954 100644 --- a/pmm_qa/pdpgsql_pgsm_setup.yml +++ b/pmm_qa/pdpgsql_pgsm_setup.yml @@ -81,3 +81,21 @@ shell: "{{ item }}" with_items: - docker exec {{ pdpgsql_pgsm_container }} bash ./pgsm_run_queries.sh & + + - name: Copy a file into the container + community.docker.docker_container_copy_into: + container: "{{ pdpgsql_pgsm_container }}" + path: ./scripts/pgsql_load.sql + container_path: /pgsql_load.sql + + - name: Create database if it doesn't exist + community.docker.docker_container_exec: + container: "{{ pdpgsql_pgsm_container }}" + command: > + psql -U {{ db_user }} -c "CREATE DATABASE school;" + + - name: Run SQL script using docker exec + community.docker.docker_container_exec: + container: "{{ pdpgsql_pgsm_container }}" + command: > + psql -U postgres -d school -f /pgsql_load.sql diff --git a/pmm_qa/percona_server/percona-server-setup.yml b/pmm_qa/percona_server/percona-server-setup.yml index f0602ca5..4af81dcd 100644 --- a/pmm_qa/percona_server/percona-server-setup.yml +++ b/pmm_qa/percona_server/percona-server-setup.yml @@ -99,7 +99,7 @@ community.docker.docker_container_exec: container: "ps_pmm_{{ ps_version }}_1" command: > - sh -c 'curl --location --insecure -u"admin:{{ admin_password }}" -s --request GET "http://{{ pmm_server_ip }}:{{ '80' if pmm_server_ip is ansible.utils.ipv4 else '8080' }}/v1/management/services" | jq -r ".services[].service_name"' + sh -c 'curl --location --insecure -u"admin:{{ admin_password }}" -s --request GET "https://{{ pmm_server_ip }}:{{ '443' if pmm_server_ip is ansible.utils.ipv4 else '8443' }}/v1/management/services" | jq -r ".services[].service_name"' register: pmm_server_services - name: Display already connected services to pmm server diff --git a/pmm_qa/scripts/pgsql_load.sql b/pmm_qa/scripts/pgsql_load.sql new file mode 100644 index 00000000..bd70b7f2 --- /dev/null +++ b/pmm_qa/scripts/pgsql_load.sql @@ -0,0 +1,91 @@ +-- ======================================== +-- CREATE TABLES +-- ======================================== + +CREATE TABLE students ( + student_id SERIAL PRIMARY KEY, + first_name VARCHAR(50), + last_name VARCHAR(50), + birth_date DATE +); + +CREATE TABLE classes ( + class_id SERIAL PRIMARY KEY, + name VARCHAR(100), + teacher VARCHAR(100) +); + +CREATE TABLE enrollments ( + enrollment_id SERIAL PRIMARY KEY, + student_id INTEGER REFERENCES students(student_id), + class_id INTEGER REFERENCES classes(class_id), + enrollment_date DATE DEFAULT CURRENT_DATE +); + +-- ======================================== +-- INSERT MOCK DATA +-- ======================================== + +INSERT INTO students (first_name, last_name, birth_date) VALUES +('Alice', 'Smith', '2005-04-10'), +('Bob', 'Johnson', '2006-08-15'), +('Charlie', 'Brown', '2004-12-01'); + +INSERT INTO classes (name, teacher) VALUES +('Mathematics', 'Mrs. Taylor'), +('History', 'Mr. Anderson'), +('Science', 'Dr. Reynolds'); + +INSERT INTO enrollments (student_id, class_id) VALUES +(1, 1), +(1, 2), +(2, 2), +(3, 1), +(3, 3); + +-- ======================================== +-- SELECT QUERIES +-- ======================================== + +-- Get all students +SELECT * FROM students; + +-- Get all students enrolled in Mathematics +SELECT s.first_name, s.last_name +FROM students s +JOIN enrollments e ON s.student_id = e.student_id +JOIN classes c ON e.class_id = c.class_id +WHERE c.name = 'Mathematics'; + +-- Count students per class +SELECT c.name, COUNT(e.student_id) AS student_count +FROM classes c +LEFT JOIN enrollments e ON c.class_id = e.class_id +GROUP BY c.name; + +-- ======================================== +-- UPDATE QUERIES +-- ======================================== + +-- Change Bob's last name +UPDATE students +SET last_name = 'Williams' +WHERE first_name = 'Bob' AND last_name = 'Johnson'; + +-- Update the teacher for the History class +UPDATE classes +SET teacher = 'Ms. Carter' +WHERE name = 'History'; + +-- ======================================== +-- DELETE QUERIES +-- ======================================== + +-- Remove Charlie from Science class +DELETE FROM enrollments +WHERE student_id = (SELECT student_id FROM students WHERE first_name = 'Charlie') + AND class_id = (SELECT class_id FROM classes WHERE name = 'Science'); + +-- Delete a student completely +DELETE FROM students +WHERE first_name = 'Alice' AND last_name = 'Smith'; From a4434eeface8c91cc6528dce3935486b25fe0884 Mon Sep 17 00:00:00 2001 From: Peter Sirotnak Date: Wed, 28 May 2025 08:03:50 +0200 Subject: [PATCH 2/2] PMM-7: 3.2.0 Fixes --- pmm_qa/pdpgsql_pgsm_setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmm_qa/pdpgsql_pgsm_setup.yml b/pmm_qa/pdpgsql_pgsm_setup.yml index a2742954..92668c69 100644 --- a/pmm_qa/pdpgsql_pgsm_setup.yml +++ b/pmm_qa/pdpgsql_pgsm_setup.yml @@ -92,7 +92,7 @@ community.docker.docker_container_exec: container: "{{ pdpgsql_pgsm_container }}" command: > - psql -U {{ db_user }} -c "CREATE DATABASE school;" + psql -U postgres -c "CREATE DATABASE school;" - name: Run SQL script using docker exec community.docker.docker_container_exec: