mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 15:26:35 +00:00
feat: moved auth method deletion to top
This commit is contained in:
@@ -13,19 +13,12 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// first we remove identities without auth method that is unused
|
// first we remove identities without auth method that is unused
|
||||||
let nullableAuthMethodIdentities = [];
|
// ! We delete all access tokens where the identity has no auth method set!
|
||||||
do {
|
// ! Which means un-configured identities that for some reason have access tokens, will have their access tokens deleted.
|
||||||
const findNullableAuthMethodIdentities = knex(TableName.Identity)
|
await knex(TableName.IdentityAccessToken)
|
||||||
.whereNull("authMethod")
|
.leftJoin(TableName.Identity, `${TableName.Identity}.id`, `${TableName.IdentityAccessToken}.identityId`)
|
||||||
.limit(BATCH_SIZE)
|
.whereNull(`${TableName.Identity}.authMethod`)
|
||||||
.select("id");
|
.delete();
|
||||||
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
nullableAuthMethodIdentities = await knex(TableName.Identity)
|
|
||||||
.whereIn("id", findNullableAuthMethodIdentities)
|
|
||||||
.del()
|
|
||||||
.returning("id");
|
|
||||||
} while (nullableAuthMethodIdentities.length > 0);
|
|
||||||
|
|
||||||
let nullableAccessTokens = await knex(TableName.IdentityAccessToken)
|
let nullableAccessTokens = await knex(TableName.IdentityAccessToken)
|
||||||
.whereNull("authMethod")
|
.whereNull("authMethod")
|
||||||
@@ -60,18 +53,6 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
console.log(`Updated ${batchIds.length} access tokens in batch <> Total updated: ${totalUpdated}`);
|
console.log(`Updated ${batchIds.length} access tokens in batch <> Total updated: ${totalUpdated}`);
|
||||||
} while (nullableAccessTokens.length > 0);
|
} while (nullableAccessTokens.length > 0);
|
||||||
|
|
||||||
// ! We delete all access tokens where the identity has no auth method set!
|
|
||||||
// ! Which means un-configured identities that for some reason have access tokens, will have their access tokens deleted.
|
|
||||||
await knex(TableName.IdentityAccessToken)
|
|
||||||
.whereNotExists((queryBuilder) => {
|
|
||||||
void queryBuilder
|
|
||||||
.select("id")
|
|
||||||
.from(TableName.Identity)
|
|
||||||
.whereRaw(`${TableName.IdentityAccessToken}."identityId" = ${TableName.Identity}.id`)
|
|
||||||
.whereNotNull("authMethod");
|
|
||||||
})
|
|
||||||
.delete();
|
|
||||||
|
|
||||||
// Finally we set the authMethod to notNullable after populating the column.
|
// Finally we set the authMethod to notNullable after populating the column.
|
||||||
// This will fail if the data is not populated correctly, so it's safe.
|
// This will fail if the data is not populated correctly, so it's safe.
|
||||||
await knex.schema.alterTable(TableName.IdentityAccessToken, (t) => {
|
await knex.schema.alterTable(TableName.IdentityAccessToken, (t) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user