Skip to content

Commit 9a458db

Browse files
committed
adding the single db test
Signed-off-by: pranav jain <pranav23iitd@gmail.com>
1 parent 1b759b7 commit 9a458db

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

test/JDBC/expected/single_db/object_ownership.out

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,3 +1140,181 @@ go
11401140
-- psql
11411141
drop user test_alter_owner_l1;
11421142
go
1143+
1144+
1145+
1146+
1147+
-- tsql
1148+
-- Create users
1149+
CREATE LOGIN partition_owner_l1 WITH PASSWORD = '[REDACTED:PASSWORD]';
1150+
GO
1151+
1152+
CREATE USER partition_owner_u1 FOR LOGIN partition_owner_l1;
1153+
GO
1154+
1155+
CREATE LOGIN partition_owner_l2 WITH PASSWORD = '[REDACTED:PASSWORD]';
1156+
GO
1157+
1158+
CREATE USER partition_owner_u2 FOR LOGIN partition_owner_l2;
1159+
GO
1160+
1161+
-- Create a schema owned by partition_owner_u1
1162+
CREATE SCHEMA test_schema AUTHORIZATION partition_owner_u1;
1163+
GO
1164+
1165+
-- Create partition function
1166+
CREATE PARTITION FUNCTION pf_test (int)
1167+
AS RANGE RIGHT FOR VALUES (100, 500, 1000);
1168+
GO
1169+
1170+
-- Create partition scheme
1171+
CREATE PARTITION SCHEME ps_test
1172+
AS PARTITION pf_test
1173+
ALL TO ([PRIMARY]);
1174+
GO
1175+
1176+
-- Create partitioned table in the user's schema
1177+
CREATE TABLE test_schema.pt_test (
1178+
id INT,
1179+
value VARCHAR(50)
1180+
) ON ps_test(id);
1181+
GO
1182+
1183+
-- Insert test data
1184+
INSERT INTO test_schema.pt_test VALUES (50, 'Value 50');
1185+
INSERT INTO test_schema.pt_test VALUES (200, 'Value 200');
1186+
INSERT INTO test_schema.pt_test VALUES (750, 'Value 750');
1187+
GO
1188+
~~ROW COUNT: 1~~
1189+
1190+
~~ROW COUNT: 1~~
1191+
1192+
~~ROW COUNT: 1~~
1193+
1194+
1195+
-- Verify parent table
1196+
SELECT name AS table_name FROM sys.tables WHERE name = 'pt_test';
1197+
GO
1198+
~~START~~
1199+
varchar
1200+
pt_test
1201+
~~END~~
1202+
1203+
1204+
-- psql
1205+
-- Check the child partition tables exist
1206+
SELECT schemaname, tablename
1207+
FROM pg_tables
1208+
WHERE tablename LIKE '%partition_%'
1209+
AND schemaname LIKE 'master_%test_schema'
1210+
ORDER BY tablename;
1211+
GO
1212+
~~START~~
1213+
name#!#name
1214+
master_test_schema#!#130a1b1b4f7de7626fc5ad270e6878f1_partition_0
1215+
master_test_schema#!#130a1b1b4f7de7626fc5ad270e6878f1_partition_1
1216+
master_test_schema#!#130a1b1b4f7de7626fc5ad270e6878f1_partition_2
1217+
master_test_schema#!#130a1b1b4f7de7626fc5ad270e6878f1_partition_3
1218+
~~END~~
1219+
1220+
1221+
-- Set GUC to allow ALTER OWNER from psql
1222+
SET babelfishpg_tsql.enable_alter_owner_from_pg = true;
1223+
GO
1224+
1225+
-- First, change the partition table owner to partition_owner_u1 (as superuser)
1226+
ALTER TABLE master_test_schema."130a1b1b4f7de7626fc5ad270e6878f1_partition_0" OWNER TO master_partition_owner_u1;
1227+
GO
1228+
1229+
-- Verify owner is now u1
1230+
SELECT tablename, tableowner
1231+
FROM pg_tables
1232+
WHERE tablename = '130a1b1b4f7de7626fc5ad270e6878f1_partition_0'
1233+
AND schemaname LIKE 'master_%test_schema';
1234+
GO
1235+
~~START~~
1236+
name#!#name
1237+
130a1b1b4f7de7626fc5ad270e6878f1_partition_0#!#master_partition_owner_u1
1238+
~~END~~
1239+
1240+
1241+
-- Grant role membership so u1 can transfer ownership to u2
1242+
GRANT master_partition_owner_u2 TO master_partition_owner_u1;
1243+
GO
1244+
1245+
-- Grant schema privileges: u1 needs USAGE to access objects, u2 needs CREATE as the new owner
1246+
GRANT ALL ON SCHEMA master_test_schema TO master_partition_owner_u1;
1247+
GO
1248+
GRANT CREATE ON SCHEMA master_test_schema TO master_partition_owner_u2;
1249+
GO
1250+
1251+
-- Switch to partition_owner_u1 (non-superuser, table owner)
1252+
SET SESSION AUTHORIZATION master_partition_owner_u1;
1253+
GO
1254+
1255+
-- Test: Change owner of child partition table as non-superuser owner
1256+
-- This tests the fix: cmd->subtype != AT_ChangeOwner allows ownership change by non-superuser owner
1257+
ALTER TABLE master_test_schema."130a1b1b4f7de7626fc5ad270e6878f1_partition_0" OWNER TO master_partition_owner_u2;
1258+
GO
1259+
1260+
-- Verify owner changed
1261+
SELECT tablename, tableowner
1262+
FROM pg_tables
1263+
WHERE tablename = '130a1b1b4f7de7626fc5ad270e6878f1_partition_0'
1264+
AND schemaname LIKE 'master_%test_schema';
1265+
GO
1266+
~~START~~
1267+
name#!#name
1268+
130a1b1b4f7de7626fc5ad270e6878f1_partition_0#!#master_partition_owner_u2
1269+
~~END~~
1270+
1271+
1272+
-- Reset to superuser
1273+
RESET SESSION AUTHORIZATION;
1274+
GO
1275+
1276+
-- Revoke the grants before cleanup
1277+
REVOKE ALL ON SCHEMA master_test_schema FROM master_partition_owner_u1;
1278+
GO
1279+
REVOKE CREATE ON SCHEMA master_test_schema FROM master_partition_owner_u2;
1280+
GO
1281+
1282+
SET babelfishpg_tsql.enable_alter_owner_from_pg = false;
1283+
GO
1284+
1285+
-- tsql
1286+
-- Verify data is still accessible
1287+
SELECT * FROM test_schema.pt_test ORDER BY id;
1288+
GO
1289+
~~START~~
1290+
int#!#varchar
1291+
50#!#Value 50
1292+
200#!#Value 200
1293+
750#!#Value 750
1294+
~~END~~
1295+
1296+
1297+
-- Cleanup
1298+
DROP TABLE test_schema.pt_test;
1299+
GO
1300+
1301+
DROP SCHEMA test_schema;
1302+
GO
1303+
1304+
DROP PARTITION SCHEME ps_test;
1305+
GO
1306+
1307+
DROP PARTITION FUNCTION pf_test;
1308+
GO
1309+
1310+
DROP USER partition_owner_u1;
1311+
GO
1312+
1313+
DROP LOGIN partition_owner_l1;
1314+
GO
1315+
1316+
DROP USER partition_owner_u2;
1317+
GO
1318+
1319+
DROP LOGIN partition_owner_l2;
1320+
GO

0 commit comments

Comments
 (0)