@@ -99,26 +99,42 @@ const queryDatabaseManifest = async (database) => {
99
99
` ) ;
100
100
101
101
// This function removes the last segment of grantee since Logto will use 'logto_tenant_fresh/alteration' for the role name.
102
- const normalizeGrantee = ( { grantee , ... rest } ) => {
103
- if ( grantee . startsWith ( 'logto_tenant_' ) ) {
104
- return { ... rest , grantee : 'logto_tenant' } ;
102
+ const normalizeRoleName = ( roleName ) => {
103
+ if ( roleName . startsWith ( 'logto_tenant_' ) ) {
104
+ return 'logto_tenant' ;
105
105
}
106
106
107
107
// Removes the last segment of region grantee since Logto will use 'logto_region_xxx' for the role name for different regions.
108
- if ( grantee . startsWith ( 'logto_region_' ) ) {
109
- return { ... rest , grantee : 'logto_region' } ;
108
+ if ( roleName . startsWith ( 'logto_region_' ) ) {
109
+ return 'logto_region' ;
110
110
}
111
111
112
- return { grantee , ... rest } ;
112
+ return roleName ;
113
113
} ;
114
114
115
+ const normalizeGrantee = ( { grantee, ...rest } ) => ( {
116
+ ...rest ,
117
+ grantee : normalizeRoleName ( grantee ) ,
118
+ } ) ;
119
+
115
120
// Ditto.
116
121
const normalizeRoles = ( { roles : raw , ...rest } ) => {
117
- const roles = raw . slice ( 1 , - 1 ) . split ( ',' ) . map ( ( name ) => name . startsWith ( 'logto_tenant_' ) ? 'logto_tenant' : name ) ;
122
+ const roles = raw
123
+ . slice ( 1 , - 1 )
124
+ . split ( ',' )
125
+ . map ( ( name ) => normalizeRoleName ( name ) ) ;
118
126
119
127
return { roles, ...rest } ;
120
128
} ;
121
129
130
+ const normalizePolicyName = ( { policyName, ...rest } ) => {
131
+ if ( policyName && policyName . startsWith ( 'allow_' ) && policyName . endsWith ( '_access' ) ) {
132
+ return { policyName : `allow_${ normalizeRoleName ( policyName . slice ( 6 , - 7 ) ) } _access` , ...rest } ;
133
+ }
134
+
135
+ return { policyName, ...rest } ;
136
+ } ;
137
+
122
138
// Omit generated ids and values
123
139
return {
124
140
tables : omitArray ( tables , 'table_catalog' ) ,
@@ -149,7 +165,7 @@ const queryDatabaseManifest = async (database) => {
149
165
indexes,
150
166
funcs,
151
167
triggers : omitArray ( triggers , 'trigger_catalog' , 'event_object_catalog' ) ,
152
- policies : policies . map ( normalizeRoles ) ,
168
+ policies : policies . map ( normalizeRoles ) . map ( normalizePolicyName ) ,
153
169
columnGrants : omitArray ( columnGrants , 'table_catalog' ) . map ( normalizeGrantee ) ,
154
170
tableGrants : omitArray ( tableGrants , 'table_catalog' ) . map ( normalizeGrantee ) ,
155
171
} ;
0 commit comments