Теперь при запуске одного из JS сервисов, будет создаваться таблицы, если их нет

This commit is contained in:
Данил 2024-10-08 20:15:20 +03:00
parent 9443efae46
commit a6c2dc7b06
3 changed files with 18 additions and 0 deletions

View file

@ -0,0 +1,14 @@
const fs = require('fs');
const pool = require('./postgresql.js');
async function create_table() {
const schema = fs.readFileSync('../shared/database/data/schema.sql', 'utf8');
for (let i = 0; i < schema.split(';').length; i++) {
try {
await pool.query(schema.split(';')[i]);
} catch (err) { continue }
}
}
module.exports = create_table;