-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-role-insert.js
More file actions
43 lines (34 loc) · 1.38 KB
/
test-role-insert.js
File metadata and controls
43 lines (34 loc) · 1.38 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
require('dotenv').config();
const { Sequelize } = require('sequelize');
const sequelize = new Sequelize(process.env.DB_PROD_URL, {
dialect: 'postgres',
dialectOptions: { ssl: { require: true, rejectUnauthorized: false } },
logging: true // Enable logging
});
async function testRoleInsert() {
try {
await sequelize.authenticate();
console.log('✅ Connected\n');
const roleId = '11111111-1111-1111-1111-111111111111';
const now = new Date().toISOString();
const query = `INSERT INTO "Roles" ("id", "name", "description", "createdAt", "updatedAt")
VALUES ('${roleId}', 'super_admin', 'Super Administrator with full system access', '${now}', '${now}')
ON CONFLICT ("id")
DO UPDATE SET
"name" = EXCLUDED."name",
"description" = EXCLUDED."description",
"updatedAt" = EXCLUDED."updatedAt"`;
console.log('Executing query:\n', query, '\n');
const result = await sequelize.query(query);
console.log('\n✅ Query executed. Result:', result);
const [roles] = await sequelize.query(`SELECT * FROM "Roles";`);
console.log('\nRoles in table:', roles);
await sequelize.close();
} catch (error) {
console.error('\n❌ Error:', error.message);
console.error('Full error:', error);
await sequelize.close();
process.exit(1);
}
}
testRoleInsert();