Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Update trusted email migration file with backfill

Tuan Dangc5cd5047d71c
diff --git a/backend/src/db/migrations/20240507032811_trusted-saml-ldap-emails.ts b/backend/src/db/migrations/20240507032811_trusted-saml-ldap-emails.ts
index 63aa75ad8f..410ee0f00e 100644
--- a/backend/src/db/migrations/20240507032811_trusted-saml-ldap-emails.ts
+++ b/backend/src/db/migrations/20240507032811_trusted-saml-ldap-emails.ts
@@ -5,9 +5,16 @@ import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> {
const isUsersTablePresent = await knex.schema.hasTable(TableName.Users);
if (isUsersTablePresent) {
- await knex.schema.alterTable(TableName.Users, (t) => {
- t.boolean("isEmailVerified");
- });
+ const hasIsEmailVerifiedColumn = await knex.schema.hasColumn(TableName.Users, "isEmailVerified");
+
+ if (!hasIsEmailVerifiedColumn) {
+ await knex.schema.alterTable(TableName.Users, (t) => {
+ t.boolean("isEmailVerified").defaultTo(false);
+ });
+ }
+
+ // Backfilling the isEmailVerified to true where isAccepted is true
+ await knex(TableName.Users).update({ isEmailVerified: true }).where("isAccepted", true);
}
const isUserAliasTablePresent = await knex.schema.hasTable(TableName.UserAliases);