73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import { getCentralPrisma } from '../src/prisma/central-prisma.service';
|
|
import * as knex from 'knex';
|
|
import * as crypto from 'crypto';
|
|
|
|
function decrypt(text: string): string {
|
|
const parts = text.split(':');
|
|
const iv = Buffer.from(parts.shift()!, 'hex');
|
|
const encryptedText = Buffer.from(parts.join(':'), 'hex');
|
|
const key = Buffer.from(process.env.ENCRYPTION_KEY, 'hex');
|
|
const decipher = crypto.createDecipheriv(
|
|
'aes-256-cbc',
|
|
key,
|
|
iv,
|
|
);
|
|
let decrypted = decipher.update(encryptedText);
|
|
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
return decrypted.toString();
|
|
}
|
|
|
|
async function updateNameField() {
|
|
const centralPrisma = getCentralPrisma();
|
|
|
|
try {
|
|
// Find tenant1
|
|
const tenant = await centralPrisma.tenant.findFirst({
|
|
where: {
|
|
OR: [
|
|
{ id: 'tenant1' },
|
|
{ slug: 'tenant1' },
|
|
],
|
|
},
|
|
});
|
|
|
|
if (!tenant) {
|
|
console.error('❌ Tenant tenant1 not found');
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`📋 Tenant: ${tenant.name} (${tenant.slug})`);
|
|
console.log(`📊 Database: ${tenant.dbName}`);
|
|
|
|
// Decrypt password
|
|
const password = decrypt(tenant.dbPassword);
|
|
|
|
// Create connection
|
|
const tenantKnex = knex.default({
|
|
client: 'mysql2',
|
|
connection: {
|
|
host: tenant.dbHost,
|
|
port: tenant.dbPort,
|
|
user: tenant.dbUsername,
|
|
password: password,
|
|
database: tenant.dbName,
|
|
},
|
|
});
|
|
|
|
// Update Account object
|
|
await tenantKnex('object_definitions')
|
|
.where({ apiName: 'Account' })
|
|
.update({ nameField: 'name' });
|
|
|
|
console.log('✅ Updated Account object nameField to "name"');
|
|
|
|
await tenantKnex.destroy();
|
|
await centralPrisma.$disconnect();
|
|
} catch (error) {
|
|
console.error('❌ Error:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
updateNameField();
|