- Add new database migrations for analysis data and job tracking - Implement enhanced document processing service with LLM integration - Add processing progress and queue status components - Create testing guides and utility scripts for CIM processing - Update frontend components for better user experience - Add environment configuration and backup files - Implement job queue service and upload progress tracking
68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
const { Pool } = require('pg');
|
|
const bcrypt = require('bcryptjs');
|
|
|
|
const pool = new Pool({
|
|
connectionString: 'postgresql://postgres:password@localhost:5432/cim_processor'
|
|
});
|
|
|
|
async function createUser() {
|
|
try {
|
|
console.log('🔍 Checking database connection...');
|
|
|
|
// Test connection
|
|
const client = await pool.connect();
|
|
console.log('✅ Database connected successfully');
|
|
|
|
// Check if users table exists
|
|
const tableCheck = await client.query(`
|
|
SELECT EXISTS (
|
|
SELECT FROM information_schema.tables
|
|
WHERE table_name = 'users'
|
|
);
|
|
`);
|
|
|
|
if (!tableCheck.rows[0].exists) {
|
|
console.log('❌ Users table does not exist. Run migrations first.');
|
|
return;
|
|
}
|
|
|
|
console.log('✅ Users table exists');
|
|
|
|
// Check existing users
|
|
const existingUsers = await client.query('SELECT email, name FROM users');
|
|
console.log('📋 Existing users:');
|
|
existingUsers.rows.forEach(user => {
|
|
console.log(` - ${user.email} (${user.name})`);
|
|
});
|
|
|
|
// Create a test user if none exist
|
|
if (existingUsers.rows.length === 0) {
|
|
console.log('👤 Creating test user...');
|
|
|
|
const hashedPassword = await bcrypt.hash('test123', 12);
|
|
|
|
const result = await client.query(`
|
|
INSERT INTO users (email, name, password, role, created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
|
RETURNING id, email, name, role
|
|
`, ['test@example.com', 'Test User', hashedPassword, 'admin']);
|
|
|
|
console.log('✅ Test user created:');
|
|
console.log(` - Email: ${result.rows[0].email}`);
|
|
console.log(` - Name: ${result.rows[0].name}`);
|
|
console.log(` - Role: ${result.rows[0].role}`);
|
|
console.log(` - Password: test123`);
|
|
} else {
|
|
console.log('✅ Users already exist in database');
|
|
}
|
|
|
|
client.release();
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
createUser();
|