don't allow users to just mount the prime db i guess for privacy reasons (may undo this someday)
This commit is contained in:
parent
464774ef4b
commit
5d7bcddcd1
4 changed files with 95 additions and 7 deletions
25
db.js
25
db.js
|
|
@ -7,6 +7,7 @@ const { Eta } = require("eta");
|
|||
const cheerio = require("cheerio");
|
||||
|
||||
const db = betterSqlite3("./dbs/0.sqlite");
|
||||
const PRIME_DB_ID = 0;
|
||||
|
||||
db.pragma("journal_mode = WAL");
|
||||
|
||||
|
|
@ -587,6 +588,7 @@ function getDbsForStructure(structureId) {
|
|||
FROM structure_dbs
|
||||
INNER JOIN dbs ON structure_dbs.db_id = dbs.id
|
||||
WHERE structure_dbs.structure_id = ?
|
||||
AND NOT (structure_dbs.db_id = ${PRIME_DB_ID} AND structure_dbs.structure_id != ${PRIME_DB_ID})
|
||||
ORDER BY structure_dbs.created_at, is_aliased ASC;
|
||||
`,
|
||||
)
|
||||
|
|
@ -607,11 +609,16 @@ function getDb(dbId) {
|
|||
function getDbForStructure(structureId, dbId) {
|
||||
return db
|
||||
.prepare(
|
||||
`SELECT *
|
||||
`SELECT
|
||||
dbs.*,
|
||||
structure_dbs.alias,
|
||||
structure_dbs.structure_id AS alias_struct_id,
|
||||
dbs.structure_id AS db_struct_id
|
||||
FROM structure_dbs
|
||||
INNER JOIN dbs ON structure_dbs.db_id = dbs.id
|
||||
WHERE structure_dbs.structure_id = ?
|
||||
AND structure_dbs.db_id = ?;
|
||||
AND structure_dbs.db_id = ?
|
||||
AND NOT (structure_dbs.db_id = ${PRIME_DB_ID} AND structure_dbs.structure_id != ${PRIME_DB_ID});
|
||||
`,
|
||||
)
|
||||
.get(structureId, dbId);
|
||||
|
|
@ -644,6 +651,9 @@ function createDb(structId, name) {
|
|||
}
|
||||
|
||||
function attachDb(structId, dbId, alias) {
|
||||
if (Number(dbId) === PRIME_DB_ID && Number(structId) !== PRIME_DB_ID) {
|
||||
throw new Error("prime db cannot be attached to other structures");
|
||||
}
|
||||
const insertStructureDbStmt = db.prepare(`
|
||||
INSERT INTO structure_dbs (db_id, structure_id, alias)
|
||||
VALUES (?, ?, ?)
|
||||
|
|
@ -698,10 +708,17 @@ function cloneStructure(
|
|||
).lastInsertRowid;
|
||||
|
||||
const dbIds = db
|
||||
.prepare(`SELECT db_id FROM structure_dbs WHERE structure_id = ?;`)
|
||||
.prepare(`SELECT db_id FROM structure_dbs WHERE structure_id = ? AND db_id != ${PRIME_DB_ID};`)
|
||||
.all(structId);
|
||||
|
||||
const toClone = new Set(cloneDbs);
|
||||
const requestedCloneDbs = Array.isArray(cloneDbs)
|
||||
? cloneDbs
|
||||
: cloneDbs
|
||||
? [cloneDbs]
|
||||
: [];
|
||||
const toClone = new Set(
|
||||
requestedCloneDbs.filter((dbId) => Number(dbId) !== PRIME_DB_ID),
|
||||
);
|
||||
const toAlias = new Set();
|
||||
|
||||
for (let { db_id } of dbIds) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue