Migrate to local PG & Update Solana Checkout
This commit is contained in:
30
scripts/init-auth.js
Normal file
30
scripts/init-auth.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const { Pool } = require('pg');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
const pool = new Pool({
|
||||
connectionString: 'postgres://postgres:Q12IqYPcJXe2VlBP3xohxZZxG8HpPxXBu4ZAXsvhnRgIwyuYpB0Q4o13fumHv2KQ@65.109.236.58:5678/postgres'
|
||||
});
|
||||
|
||||
async function run() {
|
||||
const email = 'admin@p2cgateway.com';
|
||||
const plainPassword = 'password123';
|
||||
const hash = await bcrypt.hash(plainPassword, 10);
|
||||
|
||||
console.log('Adding password_hash column if it doesn\'t exist...');
|
||||
await pool.query(`ALTER TABLE admin_users ADD COLUMN IF NOT EXISTS password_hash TEXT;`);
|
||||
|
||||
console.log('Checking if admin exists...');
|
||||
const res = await pool.query('SELECT * FROM admin_users WHERE email = $1', [email]);
|
||||
if (res.rows.length > 0) {
|
||||
console.log('Updating existing admin password...');
|
||||
await pool.query('UPDATE admin_users SET password_hash = $1 WHERE email = $2', [hash, email]);
|
||||
} else {
|
||||
console.log('Inserting new admin...');
|
||||
await pool.query('INSERT INTO admin_users (email, password_hash) VALUES ($1, $2)', [email, hash]);
|
||||
}
|
||||
|
||||
console.log('Done!');
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
run().catch(console.error);
|
||||
Reference in New Issue
Block a user