diff --git a/.github/workflows/alteration-compatibility-integration-test.yml b/.github/workflows/alteration-compatibility-integration-test.yml index c01335b53..ef4acc55f 100644 --- a/.github/workflows/alteration-compatibility-integration-test.yml +++ b/.github/workflows/alteration-compatibility-integration-test.yml @@ -5,7 +5,6 @@ on: push: branches: - master - - "push-action/**" pull_request: concurrency: @@ -19,8 +18,7 @@ jobs: has-alteration-changes: ${{ steps.changes-detection.outputs.has-alteration-changes }} steps: - - name: checkout head - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/packages/schemas/alterations/next-1702544178-sync-tenant-orgs.ts b/packages/schemas/alterations/next-1702544178-sync-tenant-orgs.ts index 77e95b5ea..e0a8e083a 100644 --- a/packages/schemas/alterations/next-1702544178-sync-tenant-orgs.ts +++ b/packages/schemas/alterations/next-1702544178-sync-tenant-orgs.ts @@ -82,7 +82,6 @@ const alteration: AlterationScript = { )}; `); - consoleLog.info('Add membership records and assign organization roles to existing users'); const usersRoles = await transaction.any<{ userId: string; roleName: string }>(sql` select public.users.id as "userId", @@ -94,37 +93,47 @@ const alteration: AlterationScript = { and public.roles.name like '%:admin'; `); - // Add membership records - await transaction.query(sql` - insert into public.organization_user_relations (tenant_id, organization_id, user_id) - values - ${sql.join( - usersRoles.map( - (userRole) => - sql`(${adminTenantId}, ${`t-${userRole.roleName.slice(0, -6)}`}, ${userRole.userId})` - ), - sql`, ` - )}; - `); - // We treat all existing users as the owner of the tenant - await transaction.query(sql` - insert into public.organization_role_user_relations (tenant_id, organization_id, user_id, organization_role_id) - values - ${sql.join( - usersRoles.map( - (userRole) => - sql` - ( - ${adminTenantId}, - ${`t-${userRole.roleName.slice(0, -6)}`}, - ${userRole.userId}, - 'owner' - ) - ` - ), - sql`, ` - )}; - `); + if (usersRoles.length === 0) { + consoleLog.warn( + 'No existing admin users found, skip adding membership records for tenant organizations.' + ); + } else { + consoleLog.info('Add membership records and assign organization roles to existing users'); + + // Add membership records + await transaction.query(sql` + insert into public.organization_user_relations (tenant_id, organization_id, user_id) + values + ${sql.join( + usersRoles.map( + (userRole) => + sql`(${adminTenantId}, ${`t-${userRole.roleName.slice(0, -6)}`}, ${ + userRole.userId + })` + ), + sql`, ` + )}; + `); + // We treat all existing users as the owner of the tenant + await transaction.query(sql` + insert into public.organization_role_user_relations (tenant_id, organization_id, user_id, organization_role_id) + values + ${sql.join( + usersRoles.map( + (userRole) => + sql` + ( + ${adminTenantId}, + ${`t-${userRole.roleName.slice(0, -6)}`}, + ${userRole.userId}, + 'owner' + ) + ` + ), + sql`, ` + )}; + `); + } consoleLog.info('Create machine-to-machine Management API role for each tenant'); await transaction.query(sql`