mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
fix: make alteration script compatible for core DB in all regions (#6494)
This commit is contained in:
parent
b61787e431
commit
19d3aa787a
1 changed files with 12 additions and 3 deletions
|
@ -40,12 +40,16 @@ const reportSubscriptionUpdatesScopeDescription =
|
|||
const alteration: AlterationScript = {
|
||||
up: async (pool) => {
|
||||
// Get the Cloud API resource
|
||||
const cloudApiResource = await pool.one<Resource>(sql`
|
||||
const cloudApiResource = await pool.maybeOne<Resource>(sql`
|
||||
select * from resources
|
||||
where tenant_id = ${adminTenantId}
|
||||
and indicator = ${cloudApiIndicator}
|
||||
`);
|
||||
|
||||
if (!cloudApiResource) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get cloud connection application role
|
||||
const tenantApplicationRole = await pool.one<Role>(sql`
|
||||
select * from roles
|
||||
|
@ -59,6 +63,7 @@ const alteration: AlterationScript = {
|
|||
values (${generateStandardId()}, ${adminTenantId}, ${
|
||||
cloudApiResource.id
|
||||
}, ${reportSubscriptionUpdatesScopeName}, ${reportSubscriptionUpdatesScopeDescription})
|
||||
on conflict (tenant_id, name, resource_id) do nothing
|
||||
returning *;
|
||||
`);
|
||||
|
||||
|
@ -67,17 +72,21 @@ const alteration: AlterationScript = {
|
|||
insert into roles_scopes (id, tenant_id, role_id, scope_id)
|
||||
values (${generateStandardId()}, ${adminTenantId}, ${tenantApplicationRole.id}, ${
|
||||
reportSubscriptionUpdatesCloudScope.id
|
||||
});
|
||||
}) on conflict (tenant_id, role_id, scope_id) do nothing;
|
||||
`);
|
||||
},
|
||||
down: async (pool) => {
|
||||
// Get the Cloud API resource
|
||||
const cloudApiResource = await pool.one<Resource>(sql`
|
||||
const cloudApiResource = await pool.maybeOne<Resource>(sql`
|
||||
select * from resources
|
||||
where tenant_id = ${adminTenantId}
|
||||
and indicator = ${cloudApiIndicator}
|
||||
`);
|
||||
|
||||
if (!cloudApiResource) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the `report:subscription:updates` scope
|
||||
await pool.query(sql`
|
||||
delete from scopes
|
||||
|
|
Loading…
Reference in a new issue