forked from cadence/out-of-your-element
Add scripts for database migration
This commit is contained in:
parent
ae3a86bff2
commit
c9bc6ac629
4 changed files with 40 additions and 2 deletions
13
db/migrations/0002-optimise-profile-content.js
Normal file
13
db/migrations/0002-optimise-profile-content.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
module.exports = async function(db) {
|
||||
const hasher = await require("xxhash-wasm")()
|
||||
const contents = db.prepare("SELECT distinct hashed_profile_content FROM sim_member").pluck().all()
|
||||
const stmt = db.prepare("UPDATE sim_member SET hashed_profile_content = ? WHERE hashed_profile_content = ?")
|
||||
db.transaction(() => {
|
||||
for (const s of contents) {
|
||||
if (!Buffer.isBuffer(s)) s = Buffer.from(s)
|
||||
const unsignedHash = hasher.h64(eventID)
|
||||
const signedHash = unsignedHash - 0x8000000000000000n // shifting down to signed 64-bit range
|
||||
stmt.run(s, signedHash)
|
||||
}
|
||||
})()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue