Skip to content

Commit 97cf7b7

Browse files
committed
adjust seed script to revised schema
1 parent 4f57399 commit 97cf7b7

2 files changed

Lines changed: 75 additions & 70 deletions

File tree

databases/catdat/scripts/seed.ts

Lines changed: 73 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ function clear_all_tables() {
6262
db.prepare(`DELETE FROM special_objects`).run()
6363
db.prepare(`DELETE FROM special_object_types`).run()
6464

65-
db.prepare(`DELETE FROM required_target_categories`).run()
65+
db.prepare(`DELETE FROM structure_map_values`).run()
6666

67-
db.prepare(`DELETE FROM implication_properties`).run()
67+
db.prepare(`DELETE FROM assumptions`).run()
68+
db.prepare(`DELETE FROM mapped_assumptions`).run()
69+
db.prepare(`DELETE FROM conclusions`).run()
6870
db.prepare(`DELETE FROM implications`).run()
6971

7072
db.prepare(`DELETE FROM property_assignments`).run()
@@ -78,6 +80,8 @@ function clear_all_tables() {
7880
db.prepare(`DELETE FROM tag_assignments`).run()
7981
db.prepare(`DELETE FROM structures`).run()
8082

83+
db.prepare(`DELETE FROM categories`).run()
84+
8185
db.prepare(`DELETE FROM tags`).run()
8286
db.prepare(`DELETE FROM relations`).run()
8387
})
@@ -144,47 +148,35 @@ function seed_config() {
144148
function seed_properties(type: StructureType) {
145149
const property_insert = db.prepare(
146150
`INSERT INTO properties (
147-
type, id, relation, description, nlab_link,
151+
name, type, relation, description, nlab_link,
148152
invariant_under_equivalences
149153
) VALUES (?, ?, ?, ?, ?, ?)`,
150154
)
151155

152156
const related_insert = db.prepare(
153-
`INSERT INTO related_properties
154-
(property_id, related_property_id)
155-
VALUES (?, ?)`,
157+
`INSERT INTO related_properties (property, related_property, type) VALUES (?, ?, ?)`,
156158
)
157159

158160
const dual_insert = db.prepare(
159-
`INSERT INTO dual_properties (type, property_id, dual_property_id)
160-
VALUES (?, ?, ?)`,
161-
)
162-
163-
const required_target_insert = db.prepare(
164-
`INSERT INTO required_target_categories (functor_property_id, category_id)
165-
VALUES (?, ?)`,
161+
`INSERT INTO dual_properties (property, dual_property, type) VALUES (?, ?, ?)`,
166162
)
167163

168164
function insert_property(property: PropertyYaml) {
169165
property_insert.run(
166+
property.id, // TODO: rename to .name
170167
type,
171-
property.id,
172168
property.relation,
173169
property.description,
174170
property.nlab_link || null,
175171
Number(property.invariant_under_equivalences),
176172
)
177173

178174
for (const related of property.related_properties) {
179-
related_insert.run(property.id, related)
175+
related_insert.run(property.id, related, type)
180176
}
181177

182178
if (property.dual_property) {
183-
dual_insert.run(type, property.id, property.dual_property)
184-
}
185-
186-
if (type === 'functor' && property.required_target) {
187-
required_target_insert.run(property.id, property.required_target)
179+
dual_insert.run(property.id, property.dual_property, type)
188180
}
189181
}
190182

@@ -206,46 +198,47 @@ function seed_structures<Struct extends StructureYaml>(
206198
) {
207199
const structure_insert = db.prepare(
208200
`INSERT INTO structures (
209-
type, id, name, notation, description, nlab_link
201+
name, type, long_name, notation, description, nlab_link
210202
) VALUES (?, ?, ?, ?, ?, ?)`,
211203
)
212204

213205
const tag_insert = db.prepare(
214-
`INSERT INTO tag_assignments (type, structure_id, tag) VALUES (?, ?, ?)`,
206+
`INSERT INTO tag_assignments (structure, type, tag) VALUES (?, ?, ?)`,
215207
)
216208

217209
const comment_insert = db.prepare(
218-
`INSERT INTO structure_comments (structure_id, comment) VALUES (?, ?)`,
210+
`INSERT INTO structure_comments (structure, type, comment) VALUES (?, ?, ?)`,
219211
)
220212

221213
const related_insert = db.prepare(
222-
`INSERT INTO related_structures (structure_id, related_structure_id) VALUES (?, ?)`,
214+
`INSERT INTO related_structures (structure, related_structure, type) VALUES (?, ?, ?)`,
223215
)
224216

225217
const property_assignment_insert = db.prepare(
226218
`INSERT INTO property_assignments (
227-
type, structure_id, property_id,
219+
type, structure, property,
228220
is_satisfied, proof, check_redundancy
229221
) VALUES (?, ?, ?, ?, ?, ?)`,
230222
)
231223

232224
function insert_property_assignments(
233-
structure_id: string,
225+
structure_name: string,
234226
entries: PropertyEntry[],
235227
is_satisfied: 0 | 1 | null,
236228
) {
237229
for (const entry of entries) {
238230
property_assignment_insert.run(
239231
type,
240-
structure_id,
232+
structure_name,
241233
entry.property,
242234
is_satisfied,
243235
entry.proof,
244236
entry.check_redundancy === false ? 0 : 1,
245237
)
246238
if (entry.proof.length >= PROOF_LENGTH_THRESHOLD) {
247239
proof_length_warnings.push({
248-
structure_id,
240+
structure: structure_name,
241+
type,
249242
property: entry.property,
250243
length: entry.proof.length,
251244
})
@@ -255,28 +248,30 @@ function seed_structures<Struct extends StructureYaml>(
255248

256249
function insert_structure(structure: Struct) {
257250
structure_insert.run(
251+
structure.id, // TODO: rename to .name
258252
type,
259-
structure.id,
260-
structure.name,
253+
structure.name, // TODO: rename to .long_name
261254
structure.notation,
262255
structure.description,
263256
structure.nlab_link,
264257
)
265258

266259
for (const tag of structure.tags) {
267-
tag_insert.run(type, structure.id, tag)
260+
tag_insert.run(structure.id, type, tag)
268261
}
269262

270263
for (const comment of structure.comments ?? []) {
271-
comment_insert.run(structure.id, comment)
264+
comment_insert.run(structure.id, type, comment)
272265
}
273266

267+
// TODO: transform
274268
for (const related of structure.related_categories ?? []) {
275-
related_insert.run(structure.id, related)
269+
related_insert.run(structure.id, related, type)
276270
}
277271

272+
// TODO: transform
278273
for (const related of structure.related_functors ?? []) {
279-
related_insert.run(structure.id, related)
274+
related_insert.run(structure.id, related, type)
280275
}
281276

282277
insert_property_assignments(structure.id, structure.satisfied_properties, 1)
@@ -303,19 +298,19 @@ function seed_structures<Struct extends StructureYaml>(
303298
*/
304299
function insert_category(category: CategoryYaml) {
305300
const category_insert = db.prepare(`
306-
INSERT INTO categories (id, objects, morphisms) VALUES (?, ?, ?)
301+
INSERT INTO categories (name, objects, morphisms) VALUES (?, ?, ?)
307302
`)
308303

309304
const dual_insert = db.prepare(`
310-
INSERT INTO dual_structures (type, structure_id, dual_structure_id)
305+
INSERT INTO dual_structures (type, structure, dual_structure)
311306
VALUES ('category', ?, ?)`)
312307

313308
const special_object_insert = db.prepare(
314-
`INSERT INTO special_objects (category_id, type, description) VALUES (?, ?, ?)`,
309+
`INSERT INTO special_objects (category, type, description) VALUES (?, ?, ?)`,
315310
)
316311

317312
const special_morphism_insert = db.prepare(
318-
`INSERT INTO special_morphisms (category_id, type, description, proof)
313+
`INSERT INTO special_morphisms (category, type, description, proof)
319314
VALUES (?, ?, ?, ?)`,
320315
)
321316

@@ -340,19 +335,17 @@ function insert_category(category: CategoryYaml) {
340335
* Inserts the data of a functor that is only relevant for functors.
341336
*/
342337
function insert_functor(functor: FunctorYaml) {
343-
const functor_insert = db.prepare(
344-
`INSERT INTO functors (id, source, target) VALUES (?, ?, ?)`,
345-
)
346-
347-
const adjoint_insert = db.prepare(
348-
`INSERT INTO adjoint_functors (left_adjoint, right_adjoint)
349-
VALUES (?, ?)`,
338+
const value_insert = db.prepare(
339+
`INSERT INTO structure_map_values
340+
(name, input, input_type, output, output_type)
341+
VALUES (?, ?, 'functor', ?, ?)`,
350342
)
351343

352-
functor_insert.run(functor.id, functor.source, functor.target)
344+
value_insert.run('source', functor.id, functor.source, 'category')
345+
value_insert.run('target', functor.id, functor.target, 'category')
353346

354347
if (functor.left_adjoint) {
355-
adjoint_insert.run(functor.left_adjoint, functor.id)
348+
value_insert.run('left_adjoint', functor.id, functor.left_adjoint, 'functor')
356349
}
357350
}
358351

@@ -362,34 +355,45 @@ function insert_functor(functor: FunctorYaml) {
362355
function seed_implications(type: StructureType) {
363356
const implication_insert = db.prepare(
364357
`INSERT INTO implications (
365-
type, id, proof, is_equivalence
358+
name, type, proof, is_equivalence
366359
) VALUES (?, ?, ?, ?)`,
367360
)
368361

369-
const implication_property_insert = db.prepare(
370-
`INSERT INTO implication_properties (
371-
type, implication_id, property_id,
372-
kind, structure
373-
) VALUES (?, ?, ?, ?, ?)`,
362+
const assumption_insert = db.prepare(
363+
`INSERT INTO assumptions (implication, property, type) VALUES (?, ?, ?)`,
364+
)
365+
366+
const mapped_assumption_insert = db.prepare(
367+
`INSERT INTO mapped_assumptions
368+
(name, implication, implication_type, property, property_type)
369+
VALUES (?, ?, ?, ?, ?)`,
370+
)
371+
372+
const conclusion_insert = db.prepare(
373+
`INSERT INTO conclusions (implication, property, type) VALUES (?, ?, ?)`,
374374
)
375375

376376
function insert_implication(impl: ImplicationYaml) {
377-
implication_insert.run(type, impl.id, impl.proof, Number(impl.is_equivalence))
378-
379-
function insert_properties(
380-
properties: string[],
381-
kind: 'assumption' | 'conclusion',
382-
structure: 'self' | 'source' | 'target',
383-
) {
384-
for (const p of properties) {
385-
implication_property_insert.run(type, impl.id, p, kind, structure)
386-
}
377+
// TODO: rename to .name in YAML files
378+
implication_insert.run(impl.id, type, impl.proof, Number(impl.is_equivalence))
379+
380+
for (const p of impl.assumptions) {
381+
assumption_insert.run(impl.id, p, type)
387382
}
388383

389-
insert_properties(impl.assumptions, 'assumption', 'self')
390-
insert_properties(impl.source_assumptions ?? [], 'assumption', 'source')
391-
insert_properties(impl.target_assumptions ?? [], 'assumption', 'target')
392-
insert_properties(impl.conclusions, 'conclusion', 'self')
384+
for (const q of impl.conclusions) {
385+
conclusion_insert.run(impl.id, q, type)
386+
}
387+
388+
for (const p of impl.source_assumptions ?? []) {
389+
// TODO: generalize
390+
mapped_assumption_insert.run('source', impl.id, type, p, 'category')
391+
}
392+
393+
for (const p of impl.target_assumptions ?? []) {
394+
// TODO: generalize
395+
mapped_assumption_insert.run('target', impl.id, type, p, 'category')
396+
}
393397
}
394398

395399
function insert_implications(implications: ImplicationYaml[]) {
@@ -413,9 +417,9 @@ function print_proof_length_warnings() {
413417

414418
proof_length_warnings.sort((a, b) => b.length - a.length)
415419

416-
for (const { structure_id, property, length } of proof_length_warnings) {
420+
for (const { structure, type, property, length } of proof_length_warnings) {
417421
console.warn(
418-
`🟡 The proof for (${structure_id}, ${property}) has ${length} characters. Consider moving it to a content page.`,
422+
`🟡 The proof for (${structure}, ${property}) of type ${type} has ${length} characters. Consider moving it to a content page.`,
419423
)
420424
}
421425
}

databases/catdat/scripts/seed.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export type ImplicationYaml = {
6464
}
6565

6666
export type ProofWarning = {
67-
structure_id: string
67+
structure: string
68+
type: string
6869
property: string
6970
length: number
7071
}

0 commit comments

Comments
 (0)