ToolJet/server/data-migrations/1762960587101-AddGroupSyncEnabledToSAMLConfigs.ts
Siddharth Pundir 33e5dfffa5
Feat/ldap group sync (#14655)
* Moving group sync for ldap from env to Ui

* Structring the code

* Resolving conflicts

* Updating the SSO Tag UI

* create app CTA fix

* Updated the length of folder name edit to the 50 character

* Handled empty space name validation in table name

* Fixed the migration for ldap and saml group sync

* Fix UI issue of The menu actions still appear when import app is selected in dashboard

* Trimmmed Extra spaces for name of app folder and workflows

* Handled table name validation

* Fix the create button int table name

* Remove extra spaces for app through import app and git repo

* Fixed the git import app issue

* Change backend validation from 32 to 31 for table name

---------

Co-authored-by: Yukti Goyal <yuktigoyal02@gmail.com>
Co-authored-by: gsmithun4 <gsmithun4@gmail.com>
2026-01-20 23:21:03 +05:30

48 lines
1.4 KiB
TypeScript

import { MigrationInterface, QueryRunner } from "typeorm";
import * as dotenv from 'dotenv';
import * as fs from 'fs';
import { filePathForEnvVars } from '../scripts/database-config-utils';
export class AddGroupSyncEnabledToSAMLConfigs1762960587101 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
let data: any = process.env;
const envVarsFilePath = filePathForEnvVars(process.env.NODE_ENV);
if (fs.existsSync(envVarsFilePath)) {
const envFileContent = fs.readFileSync(envVarsFilePath);
const parsedEnvVars = dotenv.parse(envFileContent);
data = { ...data, ...parsedEnvVars };
}
const rawValue = data.DISABLE_SAML_GROUP_SYNC;
// Rule:
// DISABLE_SAML_GROUP_SYNC = "false" --> desiredBool = true
// otherwise → false
const desiredBool = rawValue !== 'true';
const sqlBool = String(desiredBool);
// Update SAML
await queryRunner.query(`
UPDATE sso_configs
SET configs = jsonb_set(
configs::jsonb,
'{groupSyncEnabled}',
'${sqlBool}'::jsonb,
true
)
WHERE sso = 'saml'
AND NOT (configs::jsonb ? 'groupSyncEnabled');
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE sso_configs
SET configs = configs::jsonb - 'groupSyncEnabled'
WHERE sso = 'saml';
`);
}
}