-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.js
38 lines (30 loc) · 1.08 KB
/
migrate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const DATABASENAME = "data.sqlite"
const sqlite3 = require('sqlite3').verbose()
const db = new sqlite3.Database(DATABASENAME)
const runDB = (sql) => new Promise((resolve, reject)=>{
db.run(sql,(err)=>{
if(err){reject()}
resolve()
})
})
const get = (sql) => new Promise((resolve, reject)=>{
db.all(sql, (error, row) => {
if(error){reject()}
resolve(row)
})
})
!async function(){
//await runDB("alter table node add column isEndNode bool;")
const toots = await get("select Max(nodeNum) as count, tootId-100000000000000000 as tootId from node group by tootId;")
//ケタが多すぎて落ちるので桁併せて扱う
await runDB("update node set isEndNode=false;")
console.log(toots)
for(let toot of toots){
const tootId = toot.tootId
const count = toot.count
const sql = `update node set isEndNode=true where tootId=${tootId}+100000000000000000 and nodeNum=${count}`
await runDB(sql)
.catch((e)=>console.error(e))
console.log(sql)
}
}()