0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-13 21:30:30 -05:00

fix: make alteration script compatible for core DB in all regions (#6494)

This commit is contained in:
Darcy Ye 2024-08-22 10:24:55 +08:00 committed by GitHub
parent b61787e431
commit 19d3aa787a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,12 +40,16 @@ const reportSubscriptionUpdatesScopeDescription =
const alteration: AlterationScript = { const alteration: AlterationScript = {
up: async (pool) => { up: async (pool) => {
// Get the Cloud API resource // Get the Cloud API resource
const cloudApiResource = await pool.one<Resource>(sql` const cloudApiResource = await pool.maybeOne<Resource>(sql`
select * from resources select * from resources
where tenant_id = ${adminTenantId} where tenant_id = ${adminTenantId}
and indicator = ${cloudApiIndicator} and indicator = ${cloudApiIndicator}
`); `);
if (!cloudApiResource) {
return;
}
// Get cloud connection application role // Get cloud connection application role
const tenantApplicationRole = await pool.one<Role>(sql` const tenantApplicationRole = await pool.one<Role>(sql`
select * from roles select * from roles
@ -59,6 +63,7 @@ const alteration: AlterationScript = {
values (${generateStandardId()}, ${adminTenantId}, ${ values (${generateStandardId()}, ${adminTenantId}, ${
cloudApiResource.id cloudApiResource.id
}, ${reportSubscriptionUpdatesScopeName}, ${reportSubscriptionUpdatesScopeDescription}) }, ${reportSubscriptionUpdatesScopeName}, ${reportSubscriptionUpdatesScopeDescription})
on conflict (tenant_id, name, resource_id) do nothing
returning *; returning *;
`); `);
@ -67,17 +72,21 @@ const alteration: AlterationScript = {
insert into roles_scopes (id, tenant_id, role_id, scope_id) insert into roles_scopes (id, tenant_id, role_id, scope_id)
values (${generateStandardId()}, ${adminTenantId}, ${tenantApplicationRole.id}, ${ values (${generateStandardId()}, ${adminTenantId}, ${tenantApplicationRole.id}, ${
reportSubscriptionUpdatesCloudScope.id reportSubscriptionUpdatesCloudScope.id
}); }) on conflict (tenant_id, role_id, scope_id) do nothing;
`); `);
}, },
down: async (pool) => { down: async (pool) => {
// Get the Cloud API resource // Get the Cloud API resource
const cloudApiResource = await pool.one<Resource>(sql` const cloudApiResource = await pool.maybeOne<Resource>(sql`
select * from resources select * from resources
where tenant_id = ${adminTenantId} where tenant_id = ${adminTenantId}
and indicator = ${cloudApiIndicator} and indicator = ${cloudApiIndicator}
`); `);
if (!cloudApiResource) {
return;
}
// Remove the `report:subscription:updates` scope // Remove the `report:subscription:updates` scope
await pool.query(sql` await pool.query(sql`
delete from scopes delete from scopes