This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/server/migrate.js

24 lines
742 B
JavaScript
Raw Normal View History

2020-10-12 02:46:26 -07:00
const dbConnection = require('./db');
async function migrate() {
const db = await dbConnection();
await db.migrate({migrationsPath: __dirname + '/../migrations'})
2021-05-18 09:23:52 -07:00
await db.close();
2020-10-12 02:46:26 -07:00
}
migrate();
2021-07-14 06:28:53 -07:00
// temporary code for a non-sqlite migration:
const normalise = s => s.trim().toLowerCase();
async function populateUsernameNorm() {
const db = await dbConnection();
for ({id, username} of await db.all(`SELECT id, username FROM users WHERE usernameNorm IS NULL`)) {
const norm = normalise(username); // username is safe, so so will be norm
console.log(username, norm)
await db.all(`UPDATE users SET usernameNorm = '${norm}' WHERE id = '${id}'`);
}
await db.close();
}
populateUsernameNorm();