@@ -2,7 +2,11 @@ import fs from 'node:fs'
22import path from 'node:path'
33import { get_client } from './shared'
44import YAML from 'yaml'
5- import type { CategoryYaml , ConfigYaml } from './yaml.types'
5+ import type {
6+ CategoryYaml ,
7+ ConfigYaml ,
8+ PropertyYaml as CategoryPropertyYaml ,
9+ } from './yaml.types'
610
711const db = get_client ( )
812
@@ -20,6 +24,16 @@ function seed() {
2024
2125 seed_config ( )
2226
27+ const category_properties = get_category_properties ( )
28+
29+ for ( const property of category_properties ) {
30+ seed_category_property ( property )
31+ }
32+
33+ for ( const property of category_properties ) {
34+ seed_related_and_dual_properties ( property )
35+ }
36+
2337 const categories = get_categories ( )
2438
2539 for ( const category of categories ) {
@@ -226,3 +240,54 @@ function seed_related_and_dual_categories(category: CategoryYaml) {
226240 ) . run ( category . id , rel )
227241 }
228242}
243+
244+ function get_category_properties ( ) {
245+ const properties : CategoryPropertyYaml [ ] = [ ]
246+
247+ const property_files = fs
248+ . readdirSync ( path . join ( data_folder , 'category-properties' ) )
249+ . filter ( ( file ) => file . endsWith ( '.yaml' ) )
250+ . sort ( )
251+
252+ for ( const property_file of property_files ) {
253+ const property_file_content = fs . readFileSync (
254+ path . join ( data_folder , 'category-properties' , property_file ) ,
255+ 'utf8' ,
256+ )
257+
258+ const property = YAML . parse ( property_file_content )
259+ properties . push ( property )
260+ }
261+
262+ return properties
263+ }
264+
265+ function seed_category_property ( property : CategoryPropertyYaml ) {
266+ db . prepare (
267+ `INSERT INTO category_properties
268+ (id, relation, description, nlab_link,
269+ dual_property_id, invariant_under_equivalences)
270+ VALUES (?, ?, ?, ?, ?, ?)` ,
271+ ) . run ( [
272+ property . id ,
273+ property . relation ,
274+ property . description ,
275+ property . nlab_link || null ,
276+ null ,
277+ Number ( property . invariant_under_equivalences ) ,
278+ ] )
279+ }
280+
281+ function seed_related_and_dual_properties ( property : CategoryPropertyYaml ) {
282+ if ( property . dual_property_id ) {
283+ db . prepare (
284+ `UPDATE category_properties SET dual_property_id = ? WHERE id = ?` ,
285+ ) . run ( property . dual_property_id , property . id )
286+ }
287+
288+ for ( const rel of property . related_properties ) {
289+ db . prepare (
290+ `INSERT INTO related_category_properties (property_id, related_property_id) VALUES (?, ?)` ,
291+ ) . run ( property . id , rel )
292+ }
293+ }
0 commit comments