Skip to content

Commit f3afc54

Browse files
vkuttypCopilot
andcommitted
fix: add MSSQL seed script and fix MySQL/PostgreSQL seed data
- Create Tests/Resources/mssql_seed.sql with full schema (TypesTable, Employees, Departments, BulkTestTable) and stored procedures (sp_GetEmployeeById, sp_GetEmployeesByDepartment, sp_InsertEmployee, sp_GetDepartmentSummary, sp_GetEmployeesAsJSON) - Add 'Seed SQL Server database' CI step using docker exec + docker cp - Fix mysql_seed.sql: rename dept 5 Finance→Operations, Engineering budget 500000→1500000, add is_manager column with Alice as manager, add stored procedures (add_numbers, get_department_budget, get_employee_count) - Fix postgres_seed.sql: same dept/budget fixes, add is_manager BOOLEAN, add PL/pgSQL functions (add_numbers, get_department_budget, get_employee_count) - Make employees.email nullable in PostgreSQL seed (Carol White has no email) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2b6dfad commit f3afc54

4 files changed

Lines changed: 332 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ jobs:
121121
echo "Waiting for SQL Server... ($i/30)"; sleep 5
122122
done
123123
124+
- name: Seed SQL Server database
125+
run: |
126+
container_id=$(docker ps --filter "ancestor=mcr.microsoft.com/mssql/server:2022-latest" \
127+
--format "{{.ID}}" | head -1)
128+
docker cp Tests/Resources/mssql_seed.sql "$container_id:/tmp/seed.sql"
129+
docker exec "$container_id" /opt/mssql-tools18/bin/sqlcmd \
130+
-S localhost -U sa -P 'aBCD111!' -C -i /tmp/seed.sql
131+
124132
- name: Run MSSQL tests
125133
env:
126134
MSSQL_TEST_HOST: "127.0.0.1"

Tests/Resources/mssql_seed.sql

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
-- MSSQL seed data for sql-nio integration tests
2+
-- Run against MSSQLNioTestDb before executing MSSQLNioTests
3+
4+
USE MSSQLNioTestDb;
5+
GO
6+
7+
-- ─── Departments ─────────────────────────────────────────────────────────────
8+
9+
CREATE TABLE Departments (
10+
id INT IDENTITY(1,1) PRIMARY KEY,
11+
name NVARCHAR(100) NOT NULL,
12+
budget DECIMAL(14,2) DEFAULT 0.00
13+
);
14+
15+
INSERT INTO Departments (name, budget) VALUES
16+
('Engineering', 1500000.00),
17+
('Sales', 800000.50),
18+
('HR', 400000.00),
19+
('Operations', 600000.00),
20+
('Marketing', 300000.00);
21+
22+
-- ─── Employees ───────────────────────────────────────────────────────────────
23+
-- 5 employees total; 2 in dept=1 (Engineering)
24+
-- Marketing (dept=5) has 0 employees for sp_GetEmployeesByDepartment dept=5 test
25+
26+
CREATE TABLE Employees (
27+
id UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY,
28+
name NVARCHAR(100) NOT NULL,
29+
email NVARCHAR(150) NULL,
30+
salary DECIMAL(10,2) NOT NULL,
31+
department_id INT NOT NULL REFERENCES Departments(id),
32+
is_active BIT DEFAULT 1,
33+
notes NVARCHAR(MAX) NULL,
34+
hire_date DATE NULL
35+
);
36+
37+
-- Alphabetical order: Alice, Bob, Carol, Dave, Eve
38+
-- dept=1 avg_salary = (95000 + 85000) / 2 = 90000
39+
INSERT INTO Employees (name, email, salary, department_id, is_active, notes, hire_date) VALUES
40+
('Alice Johnson', 'alice@example.com', 95000.00, 1, 1,
41+
'Senior engineer and team lead with 10 years of experience', '2015-03-01'),
42+
('Bob Smith', 'bob@example.com', 85000.00, 1, 1,
43+
NULL, '2018-06-15'),
44+
('Carol White', NULL, 65000.00, 2, 1,
45+
NULL, '2019-01-10'),
46+
('Dave Brown', 'dave@example.com', 55000.00, 3, 0,
47+
NULL, '2020-07-20'),
48+
('Eve Davis', 'eve@example.com', 70000.00, 4, 1,
49+
NULL, '2021-09-05');
50+
51+
-- ─── TypesTable ──────────────────────────────────────────────────────────────
52+
53+
CREATE TABLE TypesTable (
54+
id INT IDENTITY(1,1) PRIMARY KEY,
55+
col_int INT NULL,
56+
col_int_null INT NULL,
57+
col_bigint BIGINT NULL,
58+
col_smallint SMALLINT NULL,
59+
col_tinyint TINYINT NULL,
60+
col_bit BIT NULL,
61+
col_bit_null BIT NULL,
62+
col_decimal DECIMAL(12,4) NULL,
63+
col_decimal_null DECIMAL(10,2) NULL,
64+
col_float FLOAT NULL,
65+
col_real REAL NULL,
66+
col_money MONEY NULL,
67+
col_smallmoney SMALLMONEY NULL,
68+
col_money_null MONEY NULL,
69+
col_smallmoney_null SMALLMONEY NULL,
70+
col_datetime DATETIME NULL,
71+
col_datetime_null DATETIME NULL,
72+
col_smalldatetime SMALLDATETIME NULL,
73+
col_nvarchar NVARCHAR(200) NULL,
74+
col_nvarchar_null NVARCHAR(200) NULL,
75+
col_nvarchar_max NVARCHAR(MAX) NULL,
76+
col_varchar VARCHAR(100) NULL,
77+
col_uniqueidentifier UNIQUEIDENTIFIER NULL,
78+
col_uniqueid_null UNIQUEIDENTIFIER NULL,
79+
col_date DATE NULL,
80+
col_date_null DATE NULL,
81+
col_time TIME(7) NULL,
82+
col_time_null TIME(7) NULL,
83+
col_datetime2 DATETIME2(7) NULL,
84+
col_datetime2_null DATETIME2(7) NULL,
85+
col_dtoffset DATETIMEOFFSET(7) NULL,
86+
col_dtoffset_null DATETIMEOFFSET NULL,
87+
col_text TEXT NULL,
88+
col_ntext NTEXT NULL,
89+
col_image IMAGE NULL
90+
);
91+
92+
-- Row 1: all non-null values
93+
INSERT INTO TypesTable (
94+
col_int, col_int_null,
95+
col_bigint, col_smallint, col_tinyint,
96+
col_bit, col_bit_null,
97+
col_decimal, col_decimal_null,
98+
col_float, col_real,
99+
col_money, col_smallmoney, col_money_null, col_smallmoney_null,
100+
col_datetime, col_datetime_null,
101+
col_smalldatetime,
102+
col_nvarchar, col_nvarchar_null,
103+
col_nvarchar_max,
104+
col_varchar,
105+
col_uniqueidentifier, col_uniqueid_null,
106+
col_date, col_date_null,
107+
col_time, col_time_null,
108+
col_datetime2, col_datetime2_null,
109+
col_dtoffset, col_dtoffset_null,
110+
col_text, col_ntext, col_image
111+
) VALUES (
112+
42, NULL,
113+
9223372036854775807, 32767, 255,
114+
1, NULL,
115+
12345.6789, NULL,
116+
3.14159265358979, 2.718,
117+
1234.5678, 99.99, 9.99, 1.23,
118+
'2024-01-15 10:30:00', NULL,
119+
'2024-01-15 10:30:00',
120+
N'Hello, World!', NULL,
121+
N'This is a test of NVARCHAR(MAX) column storing large content',
122+
'varchar_value',
123+
'6F9619FF-8B86-D011-B42D-00C04FC964FF', NULL,
124+
'2025-03-15', '2024-12-31',
125+
'13:45:30.1234567', NULL,
126+
'2025-03-15 13:45:30', '2025-01-01 00:00:00',
127+
CAST('2025-03-15 13:45:30.0000000 +05:30' AS DATETIMEOFFSET), NULL,
128+
'Hello from TEXT', N'Hello from NTEXT', 0xDEADBEEF
129+
);
130+
131+
-- Row 2: null variants + edge-case values
132+
INSERT INTO TypesTable (
133+
col_int, col_int_null,
134+
col_bigint, col_smallint, col_tinyint,
135+
col_bit, col_bit_null,
136+
col_decimal, col_decimal_null,
137+
col_float, col_real,
138+
col_money, col_smallmoney, col_money_null, col_smallmoney_null,
139+
col_datetime, col_datetime_null,
140+
col_smalldatetime,
141+
col_nvarchar, col_nvarchar_null,
142+
col_nvarchar_max,
143+
col_varchar,
144+
col_uniqueidentifier, col_uniqueid_null,
145+
col_date, col_date_null,
146+
col_time, col_time_null,
147+
col_datetime2, col_datetime2_null,
148+
col_dtoffset, col_dtoffset_null,
149+
col_text, col_ntext, col_image
150+
) VALUES (
151+
200, 100,
152+
-9223372036854775808, -32768, 0,
153+
0, 1,
154+
0.0001, 99.99,
155+
1.0, 1.0,
156+
0.00, 0.00, NULL, NULL,
157+
'1900-01-01 00:00:00', '2099-12-31',
158+
'2000-01-01 00:00:00',
159+
N'Ünïcödé テスト 中文', NULL,
160+
NULL,
161+
'row2',
162+
'550E8400-E29B-41D4-A716-446655440001', '550E8400-E29B-41D4-A716-446655440000',
163+
'2000-01-01', NULL,
164+
'00:00:00', NULL,
165+
'2000-01-01 00:00:00', NULL,
166+
CAST('2000-01-01 00:00:00.0000000 +00:00' AS DATETIMEOFFSET), NULL,
167+
NULL, N'Row 2 ntext', 0x00
168+
);
169+
170+
-- Update row 2 col_nvarchar_max to 5000 'X' chars (multi-packet PLP test)
171+
DECLARE @big NVARCHAR(MAX) = REPLICATE(N'X', 5000);
172+
UPDATE TypesTable SET col_nvarchar_max = @big WHERE id = 2;
173+
GO
174+
175+
-- ─── BulkTestTable ───────────────────────────────────────────────────────────
176+
177+
CREATE TABLE BulkTestTable (
178+
id INT IDENTITY(1,1) PRIMARY KEY,
179+
name NVARCHAR(100) NOT NULL,
180+
amount DECIMAL(10,2) NOT NULL,
181+
active BIT DEFAULT 1
182+
);
183+
GO
184+
185+
-- ─── Stored Procedures ───────────────────────────────────────────────────────
186+
187+
CREATE PROCEDURE sp_GetEmployeeById
188+
@p1 UNIQUEIDENTIFIER
189+
AS
190+
BEGIN
191+
SET NOCOUNT ON;
192+
SELECT id, name, email, salary, department_id, is_active, notes
193+
FROM Employees
194+
WHERE id = @p1;
195+
END;
196+
GO
197+
198+
CREATE PROCEDURE sp_GetEmployeesByDepartment
199+
@p1 INT
200+
AS
201+
BEGIN
202+
SET NOCOUNT ON;
203+
SELECT id, name, email, salary, department_id, is_active, notes
204+
FROM Employees
205+
WHERE department_id = @p1
206+
ORDER BY name;
207+
END;
208+
GO
209+
210+
CREATE PROCEDURE sp_InsertEmployee
211+
@p1 NVARCHAR(100),
212+
@p2 NVARCHAR(150),
213+
@p3 INT,
214+
@p4 DECIMAL(10,2),
215+
@p5 DATE
216+
AS
217+
BEGIN
218+
SET NOCOUNT ON;
219+
INSERT INTO Employees (name, email, department_id, salary, hire_date)
220+
OUTPUT INSERTED.id
221+
VALUES (@p1, @p2, @p3, @p4, @p5);
222+
END;
223+
GO
224+
225+
CREATE PROCEDURE sp_GetDepartmentSummary
226+
AS
227+
BEGIN
228+
SET NOCOUNT ON;
229+
SELECT
230+
d.id,
231+
d.name,
232+
d.budget,
233+
COUNT(e.id) AS employee_count,
234+
AVG(e.salary) AS avg_salary
235+
FROM Departments d
236+
LEFT JOIN Employees e ON e.department_id = d.id
237+
GROUP BY d.id, d.name, d.budget
238+
ORDER BY d.id;
239+
END;
240+
GO
241+
242+
CREATE PROCEDURE sp_GetEmployeesAsJSON
243+
AS
244+
BEGIN
245+
SET NOCOUNT ON;
246+
SELECT id, name, email, salary, department_id, is_active
247+
FROM Employees
248+
ORDER BY name
249+
FOR JSON PATH;
250+
END;
251+
GO

Tests/Resources/mysql_seed.sql

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS employees (
1616
name VARCHAR(100) NOT NULL,
1717
email VARCHAR(150) NOT NULL UNIQUE,
1818
salary DECIMAL(10,2) DEFAULT 0.00,
19+
is_manager TINYINT(1) DEFAULT 0,
1920
FOREIGN KEY (department_id) REFERENCES departments(id)
2021
);
2122

@@ -61,23 +62,23 @@ CREATE TABLE IF NOT EXISTS order_items (
6162
-- ─── Seed data ────────────────────────────────────────────────────────────────
6263

6364
INSERT INTO departments (name, budget, active) VALUES
64-
('Engineering', 500000.00, 1),
65+
('Engineering', 1500000.00, 1),
6566
('Marketing', 200000.00, 1),
6667
('Sales', 350000.00, 1),
6768
('HR', 150000.00, 1),
68-
('Finance', 250000.00, 1);
69+
('Operations', 250000.00, 1);
6970

7071
-- 8 employees: 3 in Engineering (dept=1), 1 or 2 in each other dept
7172
-- 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);
73+
INSERT INTO employees (department_id, name, email, salary, is_manager) VALUES
74+
(1, 'Alice Johnson', 'alice@example.com', 120000.00, 1),
75+
(1, 'Bob Smith', 'bob@example.com', 95000.00, 0),
76+
(1, 'Charlie Brown', 'charlie@example.com', 88000.00, 0),
77+
(2, 'Diana Prince', 'diana@example.com', 75000.00, 1),
78+
(2, 'Eve Adams', 'eve@example.com', 72000.00, 0),
79+
(3, 'Frank Castle', 'frank@example.com', 80000.00, 0),
80+
(4, 'Grace Hopper', 'grace@example.com', 70000.00, 0),
81+
(5, 'Hank Pym', 'hank@example.com', 85000.00, 0);
8182

8283
INSERT INTO type_samples (col_bool, col_tinyint, col_smallint, col_int, col_bigint,
8384
col_float, col_double, col_decimal, col_varchar, col_text, col_date, col_datetime)
@@ -103,3 +104,24 @@ INSERT INTO order_items (order_id, product_id, quantity) VALUES
103104
(1, 3, 1),
104105
(2, 3, 1),
105106
(3, 5, 3);
107+
108+
-- ─── Stored procedures ────────────────────────────────────────────────────────
109+
110+
DELIMITER $$
111+
112+
CREATE PROCEDURE add_numbers(IN a INT, IN b INT, OUT result INT)
113+
BEGIN
114+
SET result = a + b;
115+
END$$
116+
117+
CREATE PROCEDURE get_department_budget(IN dept_id INT, OUT budget DECIMAL(12,2))
118+
BEGIN
119+
SELECT d.budget INTO budget FROM departments d WHERE d.id = dept_id;
120+
END$$
121+
122+
CREATE PROCEDURE get_employee_count(IN dept_id INT, OUT cnt INT)
123+
BEGIN
124+
SELECT COUNT(*) INTO cnt FROM employees WHERE department_id = dept_id;
125+
END$$
126+
127+
DELIMITER ;

0 commit comments

Comments
 (0)