Skip to content

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

feat: added script to rename things in migration

=6845ac0f5e55
diff --git a/backend/package.json b/backend/package.json
index ecf2905c94..4f8647eab6 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -56,7 +56,7 @@
"migration:up": "npm run auditlog-migration:up && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:up",
"migration:down": "npm run auditlog-migration:down && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:down",
"migration:list": "npm run auditlog-migration:list && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:list",
- "migration:latest": "npm run auditlog-migration:latest && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:latest",
+ "migration:latest": "node ./dist/db/rename-migrations-to-mjs.mjs && npm run auditlog-migration:latest && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:latest",
"migration:status": "npm run auditlog-migration:status && knex --knexfile ./dist/db/knexfile.mjs --client pg migrate:status",
"migration:rollback": "npm run auditlog-migration:rollback && knex --knexfile ./dist/db/knexfile.mjs migrate:rollback",
"migration:unlock": "npm run auditlog-migration:unlock && knex --knexfile ./dist/db/knexfile.mjs migrate:unlock",
diff --git a/backend/src/auto-start-migrations.ts b/backend/src/auto-start-migrations.ts
index 81401855df..88f6dea692 100644
--- a/backend/src/auto-start-migrations.ts
+++ b/backend/src/auto-start-migrations.ts
@@ -32,7 +32,7 @@ const migrationStatusCheckErrorHandler = (err: Error) => {
export const runMigrations = async ({ applicationDb, auditLogDb, logger }: TArgs) => {
try {
- // akhilmhdh(Feb 10 2025): 6 months from now remove this
+ // akhilmhdh(Feb 10 2025): 2 years from now remove this
if (isProduction) {
const migrationTable = migrationConfig.tableName;
const hasMigrationTable = await applicationDb.schema.hasTable(migrationTable);
diff --git a/backend/src/db/rename-migrations-to-mjs.ts b/backend/src/db/rename-migrations-to-mjs.ts
new file mode 100644
index 0000000000..d09b5097df
--- /dev/null
+++ b/backend/src/db/rename-migrations-to-mjs.ts
@@ -0,0 +1,56 @@
+import path from "node:path";
+
+import dotenv from "dotenv";
+
+import { initAuditLogDbConnection, initDbConnection } from "./instance";
+
+const isProduction = process.env.NODE_ENV === "production";
+
+// Update with your config settings. .
+dotenv.config({
+ path: path.join(__dirname, "../../../.env.migration")
+});
+dotenv.config({
+ path: path.join(__dirname, "../../../.env")
+});
+
+const runRename = async () => {
+ if (!isProduction) return;
+ const migrationTable = "infisical_migrations";
+ const applicationDb = initDbConnection({
+ dbConnectionUri: process.env.DB_CONNECTION_URI as string,
+ dbRootCert: process.env.DB_ROOT_CERT
+ });
+
+ const auditLogDb = process.env.AUDIT_LOGS_DB_CONNECTION_URI
+ ? initAuditLogDbConnection({
+ dbConnectionUri: process.env.AUDIT_LOGS_DB_CONNECTION_URI,
+ dbRootCert: process.env.AUDIT_LOGS_DB_ROOT_CERT
+ })
+ : undefined;
+
+ const hasMigrationTable = await applicationDb.schema.hasTable(migrationTable);
+ if (hasMigrationTable) {
+ const firstFile = (await applicationDb(migrationTable).where({}).first()) as { name: string };
+ if (firstFile?.name?.includes(".ts")) {
+ await applicationDb(migrationTable).update({
+ name: applicationDb.raw("REPLACE(name, '.ts', '.mjs')")
+ });
+ }
+ }
+ if (auditLogDb) {
+ const hasMigrationTableInAuditLog = await auditLogDb.schema.hasTable(migrationTable);
+ if (hasMigrationTableInAuditLog) {
+ const firstFile = (await auditLogDb(migrationTable).where({}).first()) as { name: string };
+ if (firstFile?.name?.includes(".ts")) {
+ await auditLogDb(migrationTable).update({
+ name: auditLogDb.raw("REPLACE(name, '.ts', '.mjs')")
+ });
+ }
+ }
+ }
+ await applicationDb.destroy();
+ await auditLogDb?.destroy();
+};
+
+void runRename();