godcrm/scripts/backend-tools/import-csv.js
GOD CRM Release f89e074dd1
Some checks failed
CI / Lint / Typecheck / Test / Build (push) Has been cancelled
CI / PostgreSQL Integration Tests (push) Has been cancelled
GOD CRM — public scrubbed snapshot
Governed substrate for autonomous agents: scoped identity (passports),
audited actions, MCP workspace. Infra IPs and secrets redacted for public release.
2026-08-10 04:01:45 +03:00

67 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from 'fs';
import { parse } from 'csv-parse/sync';
import { dbRun } from './backend/database/init.js';
import { encrypt } from './backend/utils/crypto.js';
// Путь к вашему CSV файлу
const csvPath = process.argv[2] || '/root/Services Library 1c10daec7d5a80fabc82d8a2bff880fe.csv';
async function importServices() {
console.log('📥 Importing services from CSV...');
// Читаем CSV
const fileContent = fs.readFileSync(csvPath, 'utf-8');
const records = parse(fileContent, {
columns: true,
skip_empty_lines: true
});
console.log(`Found ${records.length} services`);
// Предполагаем, что первый бизнес уже создан
// В реальном случае нужно указать ID бизнеса
const businessId = process.argv[3] || 1;
for (const record of records) {
try {
const name = record['Asset name'];
const description = record['Description'];
const url = record['URL'];
const type = record['Type'];
const status = record['Статус'] || 'active';
const price = parseFloat(record['Price ']) || 0;
const login = record['Логин'];
const password = record['пароль'];
const notes = record['Text'];
if (!name) continue;
await dbRun(`
INSERT INTO services (
business_id, name, description, url, type, status, price,
login_encrypted, password_encrypted, notes_encrypted
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [
businessId,
name,
description,
url,
type,
status,
price,
encrypt(login),
encrypt(password),
encrypt(notes)
]);
console.log(`✅ Imported: ${name}`);
} catch (err) {
console.error(`❌ Failed to import ${record['Asset name']}: ${err.message}`);
}
}
console.log('✨ Import complete!');
process.exit(0);
}
importServices();