-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Schedule items are inserted with batchInsert cuts migration time to one-tenth * add tono_encumbered transitional flag to video we can migrate to a better schema later * add active to organization * experiment with Objection as query builder (seems to beat NIH!)
- Loading branch information
Showing
15 changed files
with
341 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { fkweb } from "./fkwebDatabase" | ||
import { db } from "../db" | ||
import { FkUser, RoleUserMap, Users } from "../tableTypes" | ||
|
||
// TODO: Add date of birth, phone number, identity confirmation | ||
|
||
export const migrateUsers = async () => { | ||
const query = await fkweb<FkUser>("fk_user").select( | ||
"id", | ||
"password", | ||
"last_login", | ||
"is_superuser", | ||
"first_name", | ||
"last_name", | ||
"email", | ||
"is_active", | ||
"date_joined", | ||
"date_of_birth", | ||
"identity_confirmed", | ||
"phone_number", | ||
) | ||
|
||
await db<Users>("users").insert({ | ||
id: 0, | ||
password: "", | ||
email: "[email protected]", | ||
name: "RESERVED USER FOR MIGRATIONS", | ||
}) | ||
|
||
await Promise.all( | ||
query.map( | ||
async ({ | ||
id, | ||
password, | ||
last_login, | ||
is_superuser, | ||
first_name, | ||
last_name, | ||
email, | ||
is_active, | ||
date_joined, | ||
date_of_birth, | ||
identity_confirmed, | ||
phone_number, | ||
}) => { | ||
await db<Users>("users").insert({ | ||
id, | ||
password, | ||
banned: !is_active, | ||
email, | ||
last_logged_in_at: last_login, | ||
name: `${first_name} ${last_name}`, | ||
created_at: date_joined, | ||
}) | ||
if (is_superuser) | ||
await db<RoleUserMap>("role_user_map").insert({ user_id: id, role_id: 1 }) | ||
}, | ||
), | ||
) | ||
await db.raw("SELECT setval('users_id_seq', (SELECT MAX(id) FROM users));") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//@ts-check | ||
|
||
/** | ||
* @param {import("knex").Knex} knex | ||
*/ | ||
exports.up = async (knex) => { | ||
// Alter the "organizations" table to add an "active" column | ||
await knex.schema.alterTable("organizations", (table) => { | ||
table.boolean("active").defaultTo(false) | ||
}) | ||
} | ||
|
||
/** | ||
* @param {import("knex").Knex} knex | ||
*/ | ||
exports.down = async (knex) => { | ||
// Remove the "active" column | ||
await knex.schema.alterTable("organizations", (table) => { | ||
table.dropColumn("active") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//@ts-check | ||
|
||
// Add a tonoEncumbered field to videos to indicate copyright encumberance | ||
|
||
/** | ||
* @param {import("knex").Knex} knex | ||
*/ | ||
exports.up = async (knex) => { | ||
await knex.schema.table("videos", (table) => { | ||
table.boolean("tono_encumbered").notNullable().defaultTo(false) | ||
}) | ||
} | ||
|
||
/** | ||
* @param {import("knex").Knex} knex | ||
*/ | ||
exports.down = async (knex) => { | ||
await knex.schema.table("videos", (table) => { | ||
table.dropColumn("tono_encumbered") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { Middleware } from "koa" | ||
import { SECRET_KEY, SECRET_KEY_HEADER } from "../constants" | ||
import { IS_DEV } from "../../core/constants" | ||
import { log } from "../../core/log" | ||
|
||
export const requireSecretKey = (): Middleware => (context, next) => { | ||
if (context.get(SECRET_KEY_HEADER) !== SECRET_KEY) | ||
context.throw(400, `${SECRET_KEY_HEADER} missing or incorrect`) | ||
if (IS_DEV) { | ||
log.debug(`Permitting request without secret key in dev mode`) | ||
return next() | ||
} else context.throw(400, `${SECRET_KEY_HEADER} missing or incorrect`) | ||
|
||
return next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.