162 lines
7.9 KiB
JavaScript
162 lines
7.9 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|
|
|
const db = new sqlite3.Database('database.sqlite');
|
|
const db_old = new sqlite3.Database('old_db.sqlite');
|
|
|
|
|
|
// Створення підїздів
|
|
// const sql_1 = `SELECT * FROM areas`;
|
|
// db_old.all(sql_1, [], (err, areas) => {
|
|
// if (err) {
|
|
// throw err;
|
|
// }
|
|
|
|
// for (let i = 0; i < areas.length; i++) {
|
|
// const area = areas[i];
|
|
|
|
// if(area.type == "house"){
|
|
// // console.log(JSON.parse(area.entrance));
|
|
|
|
// db.get('SELECT * FROM house WHERE title = ? AND number = ?', [area.address_title, area.address_number], (err, house) => {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// let entrances = JSON.parse(area.entrance);
|
|
// let entrance_numbers = JSON.parse(area.entrance_number);
|
|
|
|
// for (let q = 0; q < entrances.length; q++) {
|
|
// const entrance = entrances[q];
|
|
// const number = entrance_numbers[q];
|
|
// console.log(entrance, number);
|
|
|
|
// db.run(`INSERT INTO entrance(house_id, entrance_number, title, points, points_number) VALUES(?, ?, ?, ?, ?)`,
|
|
// [
|
|
// house.id,
|
|
// q,
|
|
// `Під'їзд ${q+1}`,
|
|
// JSON.stringify(entrance),
|
|
// JSON.stringify(number)
|
|
// ],
|
|
// function (err) {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// console.log("New user entrance added with id " + this.lastID);
|
|
// }
|
|
// }
|
|
// );
|
|
// }
|
|
|
|
// // console.log(JSON.parse(area.entrance));
|
|
// }
|
|
// })
|
|
// }
|
|
// }
|
|
// });
|
|
|
|
|
|
|
|
// Міграція історії з старої БД в нову
|
|
// const sql_1 = `SELECT * FROM history ORDER BY date_start`;
|
|
// db_old.all(sql_1, [], (err, historys) => {
|
|
// if (err) {
|
|
// throw err;
|
|
// }
|
|
|
|
// for (let i = 0; i < historys.length; i++) {
|
|
// const history = historys[i];
|
|
|
|
// db_old.get('SELECT * FROM territory WHERE number = ?', [history.territory_number], (err, territory) => {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// // console.log(territory);
|
|
// let areas_id = JSON.parse(territory.areas_id)
|
|
|
|
// for (let index = 0; index < areas_id.length; index++) {
|
|
// const element = areas_id[index];
|
|
|
|
// db_old.get('SELECT * FROM areas WHERE id = ?', [element[0]], (err, area) => {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// if (area.type == "house") {
|
|
// console.log(area.address_title, area.address_number);
|
|
|
|
// db.get('SELECT * FROM house WHERE title = ? AND number = ?', [area.address_title, area.address_number], (err, house) => {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// console.log(area.address_title, area.address_number);
|
|
// console.log(house.id, element[1]);
|
|
|
|
// db.get('SELECT * FROM entrance WHERE house_id = ? AND entrance_number = ?', [house.id, element[1]], (err, entrance) => {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// console.log(house.id, element[1]);
|
|
|
|
// 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(?, ?, ?, ?, ?, ?)`,
|
|
// [
|
|
// entrance.id,
|
|
// history.name,
|
|
// history.date_start,
|
|
// history.date_end,
|
|
// history.group_number,
|
|
// history.working,
|
|
// ],
|
|
// function (err) {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// console.log("New user history added with id " + this.lastID);
|
|
// }
|
|
// }
|
|
// );
|
|
// }
|
|
// })
|
|
// }
|
|
// })
|
|
|
|
// } else {
|
|
// db.get('SELECT * FROM homestead WHERE title = ? AND number = ?', [area.address_title, area.address_number], (err, homestead) => {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } 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(?, ?, ?, ?, ?, ?)`,
|
|
// [
|
|
// homestead.id,
|
|
// history.name,
|
|
// history.date_start,
|
|
// history.date_end,
|
|
// history.group_number,
|
|
// history.working,
|
|
// ],
|
|
// function (err) {
|
|
// if (err) {
|
|
// console.error(err.message);
|
|
// } else {
|
|
// console.log("New user history added with id " + this.lastID);
|
|
// }
|
|
// }
|
|
// );
|
|
// }
|
|
// })
|
|
// }
|
|
// }
|
|
// })
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
// })
|
|
// }
|
|
// });
|
|
|