-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-admin.js
More file actions
44 lines (36 loc) · 1.37 KB
/
create-admin.js
File metadata and controls
44 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { Client } = require('pg');
const bcrypt = require('bcrypt');
async function createAdmin() {
const client = new Client({
connectionString: process.env.DATABASE_URL || 'postgresql://apcs_user:apcs_password@postgres:5432/apcs_db'
});
try {
await client.connect();
console.log('Connected to database');
// Generate password hash
const password = 'admin123';
const passwordHash = await bcrypt.hash(password, 10);
console.log('Generated password hash');
// Delete existing admin if any
await client.query("DELETE FROM users WHERE email = 'admin@apcs.com'");
// Insert admin user
const result = await client.query(
`INSERT INTO users (id, email, password_hash, name, role, created_at)
VALUES (gen_random_uuid(), $1, $2, $3, $4, NOW())
RETURNING id, email, name, role`,
['admin@apcs.com', passwordHash, 'Admin User', 'SUPERADMIN']
);
console.log('\n✅ Admin user created successfully!');
console.log('----------------------------------------');
console.log('Email:', result.rows[0].email);
console.log('Password: admin123');
console.log('Role:', result.rows[0].role);
console.log('ID:', result.rows[0].id);
console.log('----------------------------------------\n');
} catch (error) {
console.error('Error:', error);
} finally {
await client.end();
}
}
createAdmin();