fix(api): Add missing app_settings creation to auto-migrate on server start to fix 500 error on live deployments
This commit is contained in:
+33
-3
@@ -64,9 +64,9 @@ const initDb = async () => {
|
||||
console.log('Database initialized successfully.');
|
||||
|
||||
// Force promote the owner to admin (enterprise role)
|
||||
await pgPool.query("UPDATE users SET role = 'enterprise' WHERE email = 'mohan.k@cavininfotech.com'");
|
||||
await pgPool.query("UPDATE users SET role = 'enterprise' WHERE email = 'admin@cavininfotech.com'");
|
||||
await pgPool.query("UPDATE users SET role = 'enterprise' WHERE role = 'admin'");
|
||||
await pgPool.query("UPDATE users SET role = 'enterprise', is_email_verified = true WHERE email = 'mohan.k@cavininfotech.com'");
|
||||
await pgPool.query("UPDATE users SET role = 'enterprise', is_email_verified = true WHERE email = 'admin@cavininfotech.com'");
|
||||
await pgPool.query("UPDATE users SET role = 'enterprise', is_email_verified = true WHERE role = 'admin'");
|
||||
} catch (err) {
|
||||
console.error('Database initialization failed:', err);
|
||||
}
|
||||
@@ -139,6 +139,36 @@ CREATE TABLE IF NOT EXISTS qr_scans (
|
||||
scanned_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||
);`).catch(console.error);
|
||||
|
||||
pgPool.query(`
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS is_email_verified BOOLEAN DEFAULT false,
|
||||
ADD COLUMN IF NOT EXISTS email_verification_token VARCHAR(255);
|
||||
`).catch(console.error);
|
||||
|
||||
pgPool.query(`
|
||||
CREATE TABLE IF NOT EXISTS app_settings (
|
||||
key VARCHAR(100) PRIMARY KEY,
|
||||
value TEXT,
|
||||
category VARCHAR(50),
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`).then(() => {
|
||||
return pgPool.query(`
|
||||
INSERT INTO app_settings (key, value, category) VALUES
|
||||
('icici_merchant_id', '', 'payments'),
|
||||
('icici_api_key', '', 'payments'),
|
||||
('google_safe_browsing_key', '', 'security'),
|
||||
('google_client_id', '', 'auth'),
|
||||
('apple_service_id', '', 'auth'),
|
||||
('smtp_host', 'smtp.office365.com', 'smtp'),
|
||||
('smtp_port', '587', 'smtp'),
|
||||
('smtp_user', 'noreply@cavininfotech.com', 'smtp'),
|
||||
('smtp_pass', 'xmkshjlszjbkcyzb', 'smtp'),
|
||||
('smtp_secure', 'false', 'smtp')
|
||||
ON CONFLICT (key) DO NOTHING;
|
||||
`);
|
||||
}).catch(console.error);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`CK-QR API listening on port ${port}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user