Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: removed some raw query in migration and rechecked TODO comments
=359c0261c42a
diff --git a/backend/src/db/migrations/20260404140728_username-merge.ts b/backend/src/db/migrations/20260404140728_username-merge.tsindex feebb3421a..95f41d4407 100644--- a/backend/src/db/migrations/20260404140728_username-merge.ts+++ b/backend/src/db/migrations/20260404140728_username-merge.ts@@ -1,7 +1,7 @@/* eslint-disable no-await-in-loop */import { Knex } from "knex";-import { TableName } from "../schemas";+import { AccessScope, TableName } from "../schemas";export async function up(knex: Knex): Promise<void> {// ============================================================@@ -77,27 +77,31 @@ export async function up(knex: Knex): Promise<void> {if (!userIds || userIds.length < 2) continue;// Get details for all users in this group- const usersDetail = await knex.raw(- `SELECT id, username, "isEmailVerified", "isAccepted"- FROM "${TableName.Users}" WHERE id = ANY(?) ORDER BY "createdAt" ASC`,- [userIds]- );- const users = usersDetail.rows as {- id: string;- username: string;- isEmailVerified: boolean | null;- isAccepted: boolean | null;- }[];-- // Delete incomplete users (not verified OR not accepted)- const incompleteIds = users.filter((u) => !u.isEmailVerified || !u.isAccepted).map((u) => u.id);-- if (incompleteIds.length > 0) {- await knex.raw(`DELETE FROM "${TableName.Users}" WHERE id = ANY(?)`, [incompleteIds]);+ const users = await knex(TableName.Users)+ .select("id", "username", "isEmailVerified", "isAccepted")+ .whereIn("id", userIds)+ .orderBy("createdAt", "asc");++ // Find orphan users (no org membership) among duplicates+ const memberships = await knex(TableName.Membership)+ .select("actorUserId")+ .distinct("actorUserId")+ .whereIn("actorUserId", userIds)+ .where("scope", AccessScope.Organization);++ const usersWithMembership = new Set(memberships.map((r) => r.actorUserId));++ // Delete: incomplete users (not verified OR not accepted) + orphan users (no org membership)+ const deletableIds = users+ .filter((u) => !u.isEmailVerified || !u.isAccepted || !usersWithMembership.has(u.id))+ .map((u) => u.id);++ if (deletableIds.length > 0) {+ await knex(TableName.Users).whereIn("id", deletableIds).del();}// Check what's left- const remaining = users.filter((u) => !incompleteIds.includes(u.id));+ const remaining = users.filter((u) => !deletableIds.includes(u.id));// eslint-disable-next-line no-continueif (remaining.length <= 1) continue;@@ -112,11 +116,9 @@ export async function up(knex: Knex): Promise<void> {// that would conflict (unique constraint), the update will fail for that row.// So we do it in two steps: update what we can, leave the rest for CASCADE delete.try {- await knex.raw(- `UPDATE "${ref.table_name}" SET "${ref.column_name}" = ?- WHERE "${ref.column_name}" = ANY(?)`,- [winner.id, loserIds]- );+ await knex(ref.table_name)+ .whereIn(ref.column_name, loserIds)+ .update({ [ref.column_name]: winner.id });} catch {// Unique constraint violation — some rows couldn't be reassigned.// That's fine — they'll be cleaned up by CASCADE when the loser user is deleted.@@ -125,7 +127,7 @@ export async function up(knex: Knex): Promise<void> {// Now delete losers — any remaining CASCADE refs will be cleaned up,// SET NULL refs were already reassigned or will be nulled- await knex.raw(`DELETE FROM "${TableName.Users}" WHERE id = ANY(?)`, [loserIds]);+ await knex(TableName.Users).whereIn("id", loserIds).del();}}diff --git a/backend/src/ee/services/ldap-config/ldap-config-service.ts b/backend/src/ee/services/ldap-config/ldap-config-service.tsindex be8923ed27..30ac24f474 100644--- a/backend/src/ee/services/ldap-config/ldap-config-service.ts+++ b/backend/src/ee/services/ldap-config/ldap-config-service.ts@@ -423,7 +423,6 @@ export const ldapConfigServiceFactory = ({if (!organization) throw new NotFoundError({ message: `Organization with ID '${orgId}' not found` });if (userAlias) {- // TODO(auth-revamp): migration should migrate ldap users as well// Verify the existing user's stored email domain + cross-org checkconst existingUser = await userDAL.findOne({ id: userAlias.userId });if (existingUser) {diff --git a/backend/src/ee/services/license/license-dal.ts b/backend/src/ee/services/license/license-dal.tsindex d5689260d5..66895401b5 100644--- a/backend/src/ee/services/license/license-dal.ts+++ b/backend/src/ee/services/license/license-dal.ts@@ -6,7 +6,6 @@ import { DatabaseError } from "@app/lib/errors";export type TLicenseDALFactory = ReturnType<typeof licenseDALFactory>;-// TODO(auth-revamp): check the countexport const licenseDALFactory = (db: TDbClient) => {const countOfOrgMembers = async (orgId: string | null, tx?: Knex) => {try {diff --git a/backend/src/server/routes/v1/user-router.ts b/backend/src/server/routes/v1/user-router.tsindex b81869fb09..5c51c32ea2 100644--- a/backend/src/server/routes/v1/user-router.ts+++ b/backend/src/server/routes/v1/user-router.ts@@ -34,7 +34,6 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {}});- // TODO(auth-revamp): Check for all reference of UsersSchema and remove if hashedPassword is setserver.route({method: "GET",url: "/duplicate-accounts",