This commit is contained in:
2025-09-09 00:10:53 +03:00
parent 38f2a05107
commit 204fc092d7
239 changed files with 22447 additions and 9536 deletions

View File

@@ -1,7 +1,7 @@
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('database.sqlite');
const db_old = new sqlite3.Database('old_db.sqlite');
const db_old = new sqlite3.Database('db_old.sqlite');
// Створення підїздів
@@ -57,7 +57,7 @@ const db_old = new sqlite3.Database('old_db.sqlite');
// Міграція історії з старої БД в нову
// const sql_1 = `SELECT * FROM history ORDER BY date_start`;
// const sql_1 = `SELECT * FROM history WHERE date_start >= 1737667735000 ORDER BY date_start`;
// db_old.all(sql_1, [], (err, historys) => {
// if (err) {
// throw err;
@@ -98,7 +98,7 @@ const db_old = new sqlite3.Database('old_db.sqlite');
// console.log(entrance.id, house.title, house.number, entrance.title);
// db.run(`INSERT INTO entrance_history(entrance_id, name, date_start, date_end, group_number, working) VALUES(?, ?, ?, ?, ?, ?)`,
// db.run(`INSERT INTO entrance_history(entrance_id, name, date_start, date_end, group_id, working) VALUES(?, ?, ?, ?, ?, ?)`,
// [
// entrance.id,
// history.name,
@@ -127,7 +127,7 @@ const db_old = new sqlite3.Database('old_db.sqlite');
// } else {
// // console.log(house.id, house.title, house.number);
// db.run(`INSERT INTO homestead_history(homestead_id, name, date_start, date_end, group_number, working) VALUES(?, ?, ?, ?, ?, ?)`,
// db.run(`INSERT INTO homestead_history(homestead_id, name, date_start, date_end, group_id, working) VALUES(?, ?, ?, ?, ?, ?)`,
// [
// homestead.id,
// history.name,
@@ -159,3 +159,50 @@ const db_old = new sqlite3.Database('old_db.sqlite');
// }
// });
// Додавання ID вісника в entrance_history
// Оновлення кожного запису в entrance_history
db.serialize(() => {
db.all(`SELECT id, name FROM entrance_history`, (err, rows) => {
if (err) return console.error('Read error:', err.message);
const updateStmt = db.prepare(`UPDATE entrance_history SET sheep_id = ? WHERE id = ?`);
let pending = rows.length;
if (pending === 0) {
updateStmt.finalize();
db.close();
console.log('Нема записів для оновлення.');
return;
}
rows.forEach((row) => {
db.get(`SELECT id FROM sheeps WHERE name = ?`, [row.name], (err, sheep) => {
if (err) {
console.error('Search error:', err.message);
if (--pending === 0) {
updateStmt.finalize();
db.close();
console.log('Оновлення завершено (з помилками).');
}
return;
}
const sheepId = sheep ? sheep.id : 0;
updateStmt.run(sheepId, row.id, (err) => {
if (err) {
console.error(`Помилка оновлення запису ID ${row.id}:`, err.message);
}
if (--pending === 0) {
updateStmt.finalize();
db.close();
console.log('Оновлення завершено');
}
});
});
});
});
});