Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,6 +63,7 @@ const alteration: AlterationScript = {
values (${generateStandardId()}, ${adminTenantId}, ${
cloudApiResource.id
}, ${reportSubscriptionUpdatesScopeName}, ${reportSubscriptionUpdatesScopeDescription})
on conflict (tenant_id, name, resource_id) do nothing
returning *;
`);

Expand All @@ -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
Expand Down
Loading