Skip to content

Commit

Permalink
Update principal_id column in database_principals for fixed db roles
Browse files Browse the repository at this point in the history
  • Loading branch information
lohia-shalini committed Jan 6, 2025
1 parent 414c7f2 commit b5320fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 18 additions & 2 deletions contrib/babelfishpg_tsql/sql/ownership.sql
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,18 @@ AS 'babelfishpg_tsql', 'bbf_is_role_member' LANGUAGE C;
CREATE OR REPLACE VIEW sys.database_principals AS
SELECT
CAST(Ext.orig_username AS SYS.SYSNAME) AS name,
CAST(Base.oid AS INT) AS principal_id,
CAST(
CASE Ext.orig_username
WHEN 'dbo' THEN 1
WHEN 'guest' THEN 2
WHEN 'db_owner' THEN 16384
WHEN 'db_accessadmin' THEN 16385
WHEN 'db_securityadmin' THEN 16386
WHEN 'db_ddladmin' THEN 16387
WHEN 'db_datareader' THEN 16390
WHEN 'db_datawriter' THEN 16390
ELSE Base.oid
END AS INT) AS principal_id,
CAST(Ext.type AS CHAR(1)) as type,
CAST(
CASE
Expand Down Expand Up @@ -479,7 +490,12 @@ WHERE Ext.database_name = DB_NAME()
UNION ALL
SELECT
CAST(name AS SYS.SYSNAME) AS name,
CAST(-1 AS INT) AS principal_id,
CAST(
CASE name
WHEN 'public' THEN 0
WHEN 'INFORMATION_SCHEMA' THEN 3
WHEN 'sys' THEN 4
END AS INT) AS principal_id,
CAST(type AS CHAR(1)) as type,
CAST(
CASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,18 @@ AS 'babelfishpg_tsql', 'bbf_is_role_member' LANGUAGE C;
CREATE OR REPLACE VIEW sys.database_principals AS
SELECT
CAST(Ext.orig_username AS SYS.SYSNAME) AS name,
CAST(Base.oid AS INT) AS principal_id,
CAST(
CASE Ext.orig_username
WHEN 'dbo' THEN 1
WHEN 'guest' THEN 2
WHEN 'db_owner' THEN 16384
WHEN 'db_accessadmin' THEN 16385
WHEN 'db_securityadmin' THEN 16386
WHEN 'db_ddladmin' THEN 16387
WHEN 'db_datareader' THEN 16390
WHEN 'db_datawriter' THEN 16390
ELSE Base.oid
END AS INT) AS principal_id,
CAST(Ext.type AS CHAR(1)) as type,
CAST(
CASE
Expand Down Expand Up @@ -248,7 +259,12 @@ WHERE Ext.database_name = DB_NAME()
UNION ALL
SELECT
CAST(name AS SYS.SYSNAME) AS name,
CAST(-1 AS INT) AS principal_id,
CAST(
CASE name
WHEN 'public' THEN 0
WHEN 'INFORMATION_SCHEMA' THEN 3
WHEN 'sys' THEN 4
END AS INT) AS principal_id,
CAST(type AS CHAR(1)) as type,
CAST(
CASE
Expand Down

0 comments on commit b5320fb

Please sign in to comment.