Open or create a pristine database at the given path This will create all necessary tables if they don't exist.
(path: P)
| 70 | /// |
| 71 | /// This will create all necessary tables if they don't exist. |
| 72 | pub fn open<P: AsRef<Path>>(path: P) -> PristineResult<Self> { |
| 73 | // Use 8 GB cache for machines with plenty of RAM. The default |
| 74 | // redb cache is 1 GB which causes excessive page eviction when |
| 75 | // the GRAPH table grows beyond that during large imports. |
| 76 | let cache_bytes = 8 * 1024 * 1024 * 1024; // 8 GiB |
| 77 | let db = Builder::new().set_cache_size(cache_bytes).create(path)?; |
| 78 | |
| 79 | // Initialize all tables |
| 80 | let write_txn = db.begin_write()?; |
| 81 | { |
| 82 | // ID mapping tables |
| 83 | write_txn.open_table(EXTERNAL)?; |
| 84 | write_txn.open_table(INTERNAL)?; |
| 85 | write_txn.open_table(NODE_TYPES)?; |
| 86 | |
| 87 | // Graph tables |
| 88 | write_txn.open_multimap_table(GRAPH)?; |
| 89 | write_txn.open_multimap_table(INODE_GRAPH)?; |
| 90 | |
| 91 | // View tables |
| 92 | write_txn.open_table(VIEWS)?; |
| 93 | write_txn.open_table(VIEW_CHANGES)?; |
| 94 | write_txn.open_table(REV_VIEW_CHANGES)?; |
| 95 | |
| 96 | // Tree tables |
| 97 | write_txn.open_table(TREE)?; |
| 98 | write_txn.open_table(REV_TREE)?; |
| 99 | write_txn.open_table(INODES)?; |
| 100 | write_txn.open_table(REV_INODES)?; |
| 101 | write_txn.open_table(DIRECTORIES)?; |
| 102 | |
| 103 | // File index cache (mtime + size + content hash for fast status detection) |
| 104 | write_txn.open_table(FILE_INDEX)?; |
| 105 | |
| 106 | // Dependency tables |
| 107 | write_txn.open_multimap_table(DEPS)?; |
| 108 | write_txn.open_multimap_table(REV_DEPS)?; |
| 109 | write_txn.open_multimap_table(CHANGE_DEPS)?; |
| 110 | write_txn.open_multimap_table(REV_CHANGE_DEPS)?; |
| 111 | write_txn.open_table(CHANGE_DEPS_INDEXED)?; |
| 112 | |
| 113 | // State tables |
| 114 | write_txn.open_table(STATES)?; |
| 115 | write_txn.open_table(MERKLE_CHAIN)?; |
| 116 | |
| 117 | // Tag record tables |
| 118 | write_txn.open_table(TAG_RECORDS)?; |
| 119 | write_txn.open_table(TAG_NAME_INDEX)?; |
| 120 | |
| 121 | // Git SHA index (git commit SHA → entity_id) |
| 122 | write_txn.open_table(GIT_SHA_INDEX)?; |
| 123 | |
| 124 | // Session tables (Sherpa-enriched provenance data) |
| 125 | write_txn.open_table(SESSION_EVENTS)?; |
| 126 | write_txn.open_table(SESSION_TODOS)?; |
| 127 | write_txn.open_table(SESSION_PHASES)?; |
| 128 | write_txn.open_table(SESSION_INTENTS)?; |
| 129 | } |
no test coverage detected