cortex
aien-dev/cortex
Brought by drakestapleton
cortex / tests / import / oracle.sh
| 1 | #!/bin/sh |
| 2 | # oracle.sh DB : the same canonical dump as logdump, produced by the sqlite3 CLI (oracle, |
| 3 | # /usr/bin/sqlite3 3.45.1) straight from the database. typeof() guards every column: a value of a |
| 4 | # kind the log field cannot carry prints BAD and can never match. f64 bits via ieee754_to_blob(). |
| 5 | # Run it on a scratch COPY (sqlite3 may checkpoint and delete a -wal when it closes). |
| 6 | set -eu |
| 7 | db=$1 |
| 8 | S() { echo "case typeof($1) when 'null' then 'null' when 'text' then 't:'||hex($1) else 'BAD:'||typeof($1) end"; } |
| 9 | B() { echo "case typeof($1) when 'null' then 'null' when 'blob' then 'b:'||hex($1) else 'BAD:'||typeof($1) end"; } |
| 10 | F() { echo "case when typeof($1) in ('real','integer') then 'f:'||hex(ieee754_to_blob($1)) else 'BAD:'||typeof($1) end"; } |
| 11 | I() { echo "case typeof($1) when 'integer' then $1 else 'BAD:'||typeof($1) end"; } |
| 12 | /usr/bin/sqlite3 -batch -bail "$db" <<EOF |
| 13 | .mode list |
| 14 | .headers off |
| 15 | select 'CXLOG001'; |
| 16 | select 'SPACE', rowid, $(S id), $(S slug), $(S created_at) from spaces order by rowid; |
| 17 | select 'ENTITY', e.rowid, |
| 18 | coalesce((select f.rowid from entities_fts_content f where f.c0 = e.id), 0), |
| 19 | $(S e.id), $(S e.space_id), $(S e.space_slug), $(S e.entity_type), $(S e.canonical_name), |
| 20 | $(S e.content), $(S e.aliases_json), $(S e.metadata_json), $(F e.confidence), $(I e.revision), |
| 21 | $(I e.retracted), $(S e.valid_from), $(S e.valid_to), $(S e.created_at), $(B e.embedding) |
| 22 | from entities e order by e.rowid; |
| 23 | select 'CLAIM', rowid, $(S id), $(S space_id), $(S space_slug), $(S subject_entity_id), |
| 24 | $(S predicate), $(S object_entity_id), $(S literal_value_json), $(F confidence), |
| 25 | $(S metadata_json), $(I retracted), $(S created_at) from claims order by rowid; |
| 26 | select 'END records=' || ((select count(*) from spaces) + (select count(*) from entities) |
| 27 | + (select count(*) from claims)); |
| 28 | EOF |