Skip to content

Commit 286d5ed

Browse files
committed
feat: add PostgreSQL replication test for MSSQL uniqueidentifier datatype
1 parent 4eb4ffc commit 286d5ed

File tree

3 files changed

+107
-5
lines changed

3 files changed

+107
-5
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
source: MSSQL
2+
target: POSTGRES
3+
4+
defaults:
5+
mode: full-refresh
6+
7+
hooks:
8+
start:
9+
- type: query
10+
connection: '{source.name}'
11+
query: |
12+
-- Drop temp tables if they exist
13+
IF OBJECT_ID('dbo.unique_identifier_test', 'U') IS NOT NULL DROP TABLE dbo.unique_identifier_test;
14+
15+
-- Create source table with uniqueidentifier column
16+
CREATE TABLE dbo.unique_identifier_test (
17+
id INT PRIMARY KEY,
18+
guid_col UNIQUEIDENTIFIER DEFAULT NEWID(),
19+
name VARCHAR(100),
20+
created_at DATETIME DEFAULT GETDATE()
21+
);
22+
23+
-- Insert test data with specific GUIDs
24+
INSERT INTO dbo.unique_identifier_test (id, guid_col, name) VALUES
25+
(1, '6F9619FF-8B86-D011-B42D-00C04FC964FF', 'Test Record 1'),
26+
(2, 'A0E44FF6-8B86-D011-B42D-00C04FC964FF', 'Test Record 2'),
27+
(3, NEWID(), 'Test Record 3'),
28+
(4, NULL, 'Test Record 4 with NULL GUID'),
29+
(5, '12345678-1234-5678-1234-567812345678', 'Test Record 5');
30+
31+
end:
32+
- type: query
33+
connection: '{target.name}'
34+
query: |
35+
-- Verify target table structure
36+
SELECT
37+
c.COLUMN_NAME,
38+
c.DATA_TYPE,
39+
c.CHARACTER_MAXIMUM_LENGTH,
40+
c.IS_NULLABLE
41+
FROM INFORMATION_SCHEMA.COLUMNS c
42+
WHERE c.TABLE_SCHEMA = 'public'
43+
AND c.TABLE_NAME = 'unique_identifier_test2'
44+
AND c.COLUMN_NAME = 'guid_col'
45+
into: column_info
46+
47+
- type: log
48+
message: |
49+
Target column info:
50+
{store.column_info}
51+
52+
- type: check
53+
check: store.column_info[0].data_type == "uuid"
54+
success_message: "guid_col should be 'uuid' type in target PostgreSQL"
55+
56+
- type: query
57+
connection: '{target.name}'
58+
query: |
59+
-- Get all target data
60+
SELECT
61+
id,
62+
guid_col::text as guid_text,
63+
name
64+
FROM public.unique_identifier_test2
65+
ORDER BY id
66+
into: target_data
67+
68+
- type: log
69+
message: |
70+
Target data:
71+
{store.target_data}
72+
73+
- type: check
74+
check: upper(store.target_data[0].guid_text) == "6F9619FF-8B86-D011-B42D-00C04FC964FF"
75+
success_message: "GUID value for record 1 matches"
76+
77+
- type: check
78+
check: upper(store.target_data[1].guid_text) == "A0E44FF6-8B86-D011-B42D-00C04FC964FF"
79+
success_message: "GUID value for record 2 matches"
80+
81+
- type: check
82+
check: length(store.target_data[2].guid_text) == 36
83+
success_message: "GUID value for record 3 has valid format"
84+
85+
- type: check
86+
check: store.target_data[3].guid_text == nil
87+
success_message: "GUID value for record 4 is NULL as expected"
88+
89+
- type: check
90+
check: upper(store.target_data[4].guid_text) == "12345678-1234-5678-1234-567812345678"
91+
success_message: "GUID value for record 5 matches"
92+
93+
- type: query
94+
connection: '{source.name}'
95+
query: DROP TABLE dbo.unique_identifier_test;
96+
97+
- type: query
98+
connection: '{target.name}'
99+
query: DROP TABLE public.unique_identifier_test2;
100+
101+
streams:
102+
dbo.unique_identifier_test:
103+
object: public.unique_identifier_test2

cmd/sling/tests/replications/r.47.mssql_uniqueidentifier.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ target: MSSQL
33

44
defaults:
55
mode: full-refresh
6-
target_options:
7-
use_bulk: false # Disable bulk for better column type control
86

97
hooks:
108
start:

cmd/sling/tests/suite.cli.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,14 +818,15 @@
818818
819819
- id: 105
820820
name: Test MSSQL uniqueidentifier datatype preservation
821-
run: sling run -d -r cmd/sling/tests/replications/r.47.mssql_uniqueidentifier.yaml
822-
streams: 1
823-
rows: 5
821+
run: |
822+
sling run -d -r cmd/sling/tests/replications/r.47.mssql_uniqueidentifier.yaml
823+
sling run -d -r cmd/sling/tests/replications/r.47.mssql_uniqueidentifier.postgres.yaml
824824
output_contains:
825825
- "guid_col should be 'uniqueidentifier' type in target"
826826
- "GUID value for record 1 should match"
827827
- "GUID value for record 5 should match"
828828
- "execution succeeded"
829+
- "DROP TABLE public.unique_identifier_test2"
829830

830831
- id: 106
831832
name: Test MSSQL to BigQuery BIGNUMERIC conversion for high precision/scale decimals

0 commit comments

Comments
 (0)