nsmcp::AccessRecordStoreSQLite method initialize (protected)

 <instance of nsmcp::AccessRecordStoreSQLite[i]> initialize

Defined in /usr/local/ns/tcl/nsmcp/log-traffic-record-store.tcl

Testcases:
No testcase defined.
Source code:
set journal [expr {[dict exists ${:settings} unified] && [dict get ${:settings} unified] ? "WAL" : "DELETE"}]
${:db} execute "PRAGMA nsmcp_records.journal_mode=$journal"
${:db} execute {PRAGMA busy_timeout=100;
    PRAGMA nsmcp_records.synchronous=FULL; PRAGMA nsmcp_records.cache_size=-8192;
    PRAGMA nsmcp_records.mmap_size=0; PRAGMA temp_store=FILE;
    PRAGMA nsmcp_records.journal_size_limit=0}
# Reserve space for the rollback journal. The cap applies to all live
# database/journal files, not SQL temporary sort files. No SQLite settings on main are changed.
set pages [expr {wide([dict get ${:settings} maxBytes]*0.4)/[${:db} scalar {PRAGMA nsmcp_records.page_size}]}]
if {[${:db} scalar {PRAGMA nsmcp_records.page_count}]>$pages} {error "record-store-disk-limit"}
${:db} execute "PRAGMA nsmcp_records.max_page_count=$pages"
${:db} execute {CREATE TABLE IF NOT EXISTS nsmcp_records.meta(version INTEGER NOT NULL);
    INSERT INTO nsmcp_records.meta SELECT 1 WHERE NOT EXISTS(SELECT 1 FROM nsmcp_records.meta);
    CREATE TABLE IF NOT EXISTS nsmcp_records.files(fid INTEGER PRIMARY KEY AUTOINCREMENT,k TEXT UNIQUE NOT NULL,identity TEXT NOT NULL,prefix TEXT NOT NULL,plen INTEGER NOT NULL,high INTEGER NOT NULL,stamp INTEGER NOT NULL,touched INTEGER NOT NULL);
    CREATE TABLE IF NOT EXISTS nsmcp_records.ranges(fid INTEGER NOT NULL,lo INTEGER NOT NULL,hi INTEGER NOT NULL,anchor TEXT NOT NULL,PRIMARY KEY(fid,lo));
    CREATE TABLE IF NOT EXISTS nsmcp_records.rows(fid INTEGER NOT NULL,off INTEGER NOT NULL,stop INTEGER NOT NULL,kind INTEGER NOT NULL,t REAL,status INTEGER,path TEXT,method TEXT,pool TEXT,source TEXT,driver TEXT,auth TEXT,bytes INTEGER,phase INTEGER,fallback INTEGER,a REAL,q REAL,f REAL,r REAL,peer TEXT,agent TEXT,label TEXT,clipped INTEGER,redacted INTEGER,identifier TEXT,score TEXT,PRIMARY KEY(fid,off));
    CREATE INDEX IF NOT EXISTS nsmcp_records.by_time ON rows(t);
    CREATE INDEX IF NOT EXISTS nsmcp_records.by_time_status ON rows(t,status,fid,off,kind)}
set version [${:db} scalar {SELECT version FROM nsmcp_records.meta}]
if {$version ni {1 2}} {error "record-store-schema-version"}
set columns {}; foreach row [${:db} execute {SELECT name FROM pragma_table_info('rows','nsmcp_records')}] {lappend columns [dict get $row name]}
if {"completed" ni $columns} {${:db} execute {ALTER TABLE nsmcp_records.rows ADD COLUMN completed REAL NOT NULL DEFAULT 0}}
if {"rolled" ni $columns} {${:db} execute {ALTER TABLE nsmcp_records.rows ADD COLUMN rolled INTEGER NOT NULL DEFAULT 0}}
set columns {}; foreach row [${:db} execute {SELECT name FROM pragma_table_info('files','nsmcp_records')}] {lappend columns [dict get $row name]}
if {"active" ni $columns} {${:db} execute {ALTER TABLE nsmcp_records.files ADD COLUMN active INTEGER NOT NULL DEFAULT 1}}
foreach column {dropping} {
    if {$column ni $columns} {${:db} execute "ALTER TABLE nsmcp_records.files ADD COLUMN $column INTEGER NOT NULL DEFAULT 0"}
}
${:db} execute {CREATE TABLE IF NOT EXISTS nsmcp_records.state(key TEXT PRIMARY KEY,value TEXT NOT NULL);
    CREATE TABLE IF NOT EXISTS nsmcp_records.peer_addresses(k BLOB PRIMARY KEY,address TEXT NOT NULL,seen REAL NOT NULL);
    CREATE TABLE IF NOT EXISTS nsmcp_records.minutes(fid INTEGER NOT NULL,slot INTEGER NOT NULL,status INTEGER NOT NULL,pool TEXT NOT NULL,method TEXT NOT NULL,source TEXT NOT NULL,n INTEGER NOT NULL,bytes INTEGER NOT NULL,PRIMARY KEY(fid,slot,status,pool,method,source));
    CREATE INDEX IF NOT EXISTS nsmcp_records.minute_time ON minutes(slot,status);
    CREATE INDEX IF NOT EXISTS nsmcp_records.peer_expiry ON peer_addresses(seen);
    CREATE INDEX IF NOT EXISTS nsmcp_records.diagnostic_expiry ON rows(completed) WHERE kind<>0;
    CREATE INDEX IF NOT EXISTS nsmcp_records.correlation ON rows(identifier,t);
    CREATE TABLE IF NOT EXISTS nsmcp_records.evictions(id INTEGER PRIMARY KEY,dropped_at INTEGER,first_time REAL,last_time REAL,rows INTEGER,reason TEXT);
    UPDATE nsmcp_records.meta SET version=2}
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: