Skip to content

Commit da9f6ae

Browse files
vkuttypCopilot
andcommitted
fix: add DB seed scripts and fix SQL Server CI setup
- Add Tests/Resources/mysql_seed.sql with full schema + seed data (departments×5, employees×8, type_samples×1, products×6, orders, order_items) - Add Tests/Resources/postgres_seed.sql with equivalent PostgreSQL schema (uses SERIAL, BOOLEAN, NUMERIC, UUID, proper PG types) - CI: add 'Seed MySQL database' step (runs mysql_seed.sql via mysql client) - CI: add 'Seed PostgreSQL database' step (runs postgres_seed.sql via psql) - CI: install mssql-tools18 on ubuntu-24.04 runner before sqlcmd usage (runner does not have sqlcmd pre-installed; tools live inside the container) - CI: improve SQL Server wait loop (5s interval, 30 retries, idempotent CREATE) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2bda17d commit da9f6ae

46 files changed

Lines changed: 15942 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,23 @@ jobs:
109109
restore-keys: |
110110
${{ runner.os }}-spm-mssql-
111111
112+
- name: Install mssql-tools18
113+
run: |
114+
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \
115+
| sudo gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg
116+
curl -fsSL https://packages.microsoft.com/config/ubuntu/24.04/prod.list \
117+
| sudo tee /etc/apt/sources.list.d/msprod.list
118+
sudo apt-get update -q
119+
ACCEPT_EULA=Y sudo apt-get install -y -q mssql-tools18 unixodbc-dev
120+
echo "/opt/mssql-tools18/bin" >> $GITHUB_PATH
121+
112122
- name: Create test database
113123
run: |
114-
until /opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 -U sa -P 'aBCD111!' -C \
115-
-Q "CREATE DATABASE MSSQLNioTestDb" 2>/dev/null; do
116-
echo "Waiting for SQL Server..."; sleep 3
124+
for i in $(seq 1 30); do
125+
/opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 -U sa -P 'aBCD111!' -C \
126+
-Q "IF DB_ID('MSSQLNioTestDb') IS NULL CREATE DATABASE MSSQLNioTestDb" \
127+
2>/dev/null && echo "SQL Server ready." && break
128+
echo "Waiting for SQL Server... ($i/30)"; sleep 5
117129
done
118130
119131
- name: Run MSSQL tests
@@ -164,6 +176,11 @@ jobs:
164176
restore-keys: |
165177
${{ runner.os }}-spm-pg-
166178
179+
- name: Seed PostgreSQL database
180+
run: |
181+
PGPASSWORD=pgPass123 psql -h 127.0.0.1 -U pguser -d PostgresNioTestDb \
182+
-f Tests/Resources/postgres_seed.sql
183+
167184
- name: Run PostgreSQL tests
168185
env:
169186
PG_TEST_HOST: "127.0.0.1"
@@ -213,6 +230,10 @@ jobs:
213230
restore-keys: |
214231
${{ runner.os }}-spm-mysql-
215232
233+
- name: Seed MySQL database
234+
run: |
235+
mysql -h 127.0.0.1 -u mysqluser -pmysqlPass123 MySQLNioTestDb < Tests/Resources/mysql_seed.sql
236+
216237
- name: Run MySQL tests
217238
env:
218239
MYSQL_TEST_HOST: "127.0.0.1"

Tests/Resources/mysql_seed.sql

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
-- MySQL seed data for sql-nio integration tests
2+
-- Run against MySQLNioTestDb before executing MySQLNioTests
3+
4+
-- ─── Schema ───────────────────────────────────────────────────────────────────
5+
6+
CREATE TABLE IF NOT EXISTS departments (
7+
id INT AUTO_INCREMENT PRIMARY KEY,
8+
name VARCHAR(100) NOT NULL,
9+
budget DECIMAL(12,2) DEFAULT 0.00,
10+
active TINYINT(1) DEFAULT 1
11+
);
12+
13+
CREATE TABLE IF NOT EXISTS employees (
14+
id INT AUTO_INCREMENT PRIMARY KEY,
15+
department_id INT NOT NULL,
16+
name VARCHAR(100) NOT NULL,
17+
email VARCHAR(150) NOT NULL UNIQUE,
18+
salary DECIMAL(10,2) DEFAULT 0.00,
19+
FOREIGN KEY (department_id) REFERENCES departments(id)
20+
);
21+
22+
CREATE TABLE IF NOT EXISTS type_samples (
23+
id INT AUTO_INCREMENT PRIMARY KEY,
24+
col_bool TINYINT(1),
25+
col_tinyint TINYINT,
26+
col_smallint SMALLINT,
27+
col_int INT,
28+
col_bigint BIGINT,
29+
col_float FLOAT,
30+
col_double DOUBLE,
31+
col_decimal DECIMAL(12,5),
32+
col_varchar VARCHAR(100),
33+
col_text TEXT,
34+
col_date DATE,
35+
col_datetime DATETIME
36+
);
37+
38+
CREATE TABLE IF NOT EXISTS products (
39+
id INT AUTO_INCREMENT PRIMARY KEY,
40+
name VARCHAR(100) NOT NULL,
41+
price DECIMAL(10,2) DEFAULT 0.00,
42+
active TINYINT(1) DEFAULT 1
43+
);
44+
45+
CREATE TABLE IF NOT EXISTS orders (
46+
id INT AUTO_INCREMENT PRIMARY KEY,
47+
employee_id INT NOT NULL,
48+
total_amount DECIMAL(10,2) DEFAULT 0.00,
49+
FOREIGN KEY (employee_id) REFERENCES employees(id)
50+
);
51+
52+
CREATE TABLE IF NOT EXISTS order_items (
53+
id INT AUTO_INCREMENT PRIMARY KEY,
54+
order_id INT NOT NULL,
55+
product_id INT NOT NULL,
56+
quantity INT DEFAULT 1,
57+
FOREIGN KEY (order_id) REFERENCES orders(id),
58+
FOREIGN KEY (product_id) REFERENCES products(id)
59+
);
60+
61+
-- ─── Seed data ────────────────────────────────────────────────────────────────
62+
63+
INSERT INTO departments (name, budget, active) VALUES
64+
('Engineering', 500000.00, 1),
65+
('Marketing', 200000.00, 1),
66+
('Sales', 350000.00, 1),
67+
('HR', 150000.00, 1),
68+
('Finance', 250000.00, 1);
69+
70+
-- 8 employees: 3 in Engineering (dept=1), 1 or 2 in each other dept
71+
-- Alice Johnson is alphabetically first in dept=1 and has the highest salary overall
72+
INSERT INTO employees (department_id, name, email, salary) VALUES
73+
(1, 'Alice Johnson', 'alice@example.com', 120000.00),
74+
(1, 'Bob Smith', 'bob@example.com', 95000.00),
75+
(1, 'Charlie Brown', 'charlie@example.com', 88000.00),
76+
(2, 'Diana Prince', 'diana@example.com', 75000.00),
77+
(2, 'Eve Adams', 'eve@example.com', 72000.00),
78+
(3, 'Frank Castle', 'frank@example.com', 80000.00),
79+
(4, 'Grace Hopper', 'grace@example.com', 70000.00),
80+
(5, 'Hank Pym', 'hank@example.com', 85000.00);
81+
82+
INSERT INTO type_samples (col_bool, col_tinyint, col_smallint, col_int, col_bigint,
83+
col_float, col_double, col_decimal, col_varchar, col_text, col_date, col_datetime)
84+
VALUES (1, 127, 32767, 2147483647, 9223372036854775807,
85+
3.14, 2.718281828, 99999.99999, 'VarChar Value', 'Hello MySQL',
86+
'2025-06-15', '2025-06-15 10:30:00');
87+
88+
INSERT INTO products (name, price, active) VALUES
89+
('Widget A', 9.99, 1),
90+
('Widget B', 14.99, 1),
91+
('Gadget Pro', 49.99, 1),
92+
('Gadget Lite', 29.99, 1),
93+
('SuperTool', 99.99, 1),
94+
('Discontinued', 0.01, 0);
95+
96+
INSERT INTO orders (employee_id, total_amount) VALUES
97+
(1, 150.00),
98+
(2, 49.99),
99+
(3, 299.97);
100+
101+
INSERT INTO order_items (order_id, product_id, quantity) VALUES
102+
(1, 1, 5),
103+
(1, 3, 1),
104+
(2, 3, 1),
105+
(3, 5, 3);

Tests/Resources/postgres_seed.sql

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
-- PostgreSQL seed data for sql-nio integration tests
2+
-- Run against PostgresNioTestDb before executing PostgresNioTests
3+
4+
-- ─── Schema ───────────────────────────────────────────────────────────────────
5+
6+
CREATE TABLE IF NOT EXISTS departments (
7+
id SERIAL PRIMARY KEY,
8+
name TEXT NOT NULL,
9+
budget NUMERIC(12,2) DEFAULT 0,
10+
active BOOLEAN DEFAULT TRUE
11+
);
12+
13+
CREATE TABLE IF NOT EXISTS employees (
14+
id SERIAL PRIMARY KEY,
15+
department_id INT NOT NULL REFERENCES departments(id),
16+
name TEXT NOT NULL,
17+
email TEXT NOT NULL UNIQUE,
18+
salary NUMERIC(10,2) DEFAULT 0
19+
);
20+
21+
CREATE TABLE IF NOT EXISTS type_samples (
22+
id SERIAL PRIMARY KEY,
23+
col_bool BOOLEAN,
24+
col_int2 SMALLINT,
25+
col_int4 INTEGER,
26+
col_int8 BIGINT,
27+
col_float4 REAL,
28+
col_float8 DOUBLE PRECISION,
29+
col_numeric NUMERIC(14,4),
30+
col_text TEXT,
31+
col_varchar VARCHAR(100),
32+
col_date DATE,
33+
col_ts TIMESTAMP,
34+
col_uuid UUID
35+
);
36+
37+
CREATE TABLE IF NOT EXISTS products (
38+
id SERIAL PRIMARY KEY,
39+
name TEXT NOT NULL,
40+
price NUMERIC(10,2) DEFAULT 0,
41+
active BOOLEAN DEFAULT TRUE
42+
);
43+
44+
CREATE TABLE IF NOT EXISTS orders (
45+
id SERIAL PRIMARY KEY,
46+
employee_id INT NOT NULL REFERENCES employees(id),
47+
total_amount NUMERIC(10,2) DEFAULT 0
48+
);
49+
50+
CREATE TABLE IF NOT EXISTS order_items (
51+
id SERIAL PRIMARY KEY,
52+
order_id INT NOT NULL REFERENCES orders(id),
53+
product_id INT NOT NULL REFERENCES products(id),
54+
quantity INT DEFAULT 1
55+
);
56+
57+
-- ─── Seed data ────────────────────────────────────────────────────────────────
58+
59+
INSERT INTO departments (name, budget, active) VALUES
60+
('Engineering', 500000.00, TRUE),
61+
('Marketing', 200000.00, TRUE),
62+
('Sales', 350000.00, TRUE),
63+
('HR', 150000.00, TRUE),
64+
('Finance', 250000.00, TRUE);
65+
66+
-- 8 employees: 3 in Engineering (id=1), others distributed
67+
-- Alice Johnson is alphabetically first in dept=1 and highest paid overall
68+
INSERT INTO employees (department_id, name, email, salary) VALUES
69+
(1, 'Alice Johnson', 'alice@example.com', 120000.00),
70+
(1, 'Bob Smith', 'bob@example.com', 95000.00),
71+
(1, 'Charlie Brown', 'charlie@example.com', 88000.00),
72+
(2, 'Diana Prince', 'diana@example.com', 75000.00),
73+
(2, 'Eve Adams', 'eve@example.com', 72000.00),
74+
(3, 'Frank Castle', 'frank@example.com', 80000.00),
75+
(4, 'Grace Hopper', 'grace@example.com', 70000.00),
76+
(5, 'Hank Pym', 'hank@example.com', 85000.00);
77+
78+
INSERT INTO type_samples (col_bool, col_int2, col_int4, col_int8,
79+
col_float4, col_float8, col_numeric, col_text, col_varchar,
80+
col_date, col_ts, col_uuid)
81+
VALUES (TRUE, 32767, 2147483647, 9223372036854775807,
82+
3.14, 2.718281828, 99999.9999, 'Hello PostgreSQL', 'VarChar Value',
83+
'2025-06-15', '2025-06-15 10:30:00',
84+
'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11');
85+
86+
INSERT INTO products (name, price, active) VALUES
87+
('Widget A', 9.99, TRUE),
88+
('Widget B', 14.99, TRUE),
89+
('Gadget Pro', 49.99, TRUE),
90+
('Gadget Lite', 29.99, TRUE),
91+
('SuperTool', 99.99, TRUE),
92+
('Discontinued', 0.01, FALSE);
93+
94+
INSERT INTO orders (employee_id, total_amount) VALUES
95+
(1, 150.00),
96+
(2, 49.99),
97+
(3, 299.97);
98+
99+
INSERT INTO order_items (order_id, product_id, quantity) VALUES
100+
(1, 1, 5),
101+
(1, 3, 1),
102+
(2, 3, 1),
103+
(3, 5, 3);

0 commit comments

Comments
 (0)