wip(22w8c): add first-run sql config

This commit is contained in:
Cloud Shell 2022-02-25 11:07:29 +00:00
parent 547ad95c8a
commit 265d9ca6ed
2 changed files with 21 additions and 3 deletions

14
src/db/config.sql Normal file
View file

@ -0,0 +1,14 @@
CREATE TABLE flags (
k text PRIMARY KEY,
v real
);
CREATE TABLE fileindex (
anchor text PRIMARY KEY,
chksum text
);
INSERT INTO flags
VALUES
("CALC_CHECKSUM", 1),
("BUCKET_OK", 0);

View file

@ -1,4 +1,5 @@
import os
import pathlib
import sqlite3 as sqlite
from ..glob import file_exists
@ -31,12 +32,15 @@ class SQLite():
return path
def configure_db(self):
metadata_sql = "CREATE TABLE metadata (key text, value text)"
metadata = self.query(metadata_sql)
cwd = str(pathlib.Path(__file__).parent.resolve())
sql = open(cwd + "/config.sql")
sql_str = sql.read()
return self.cursor.executescript(sql_str)
def init(self):
# Set up db if it's fresh
hasmeta_sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='metadata'"
hasmeta_sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='flags'"
if not self.query(hasmeta_sql):
self.configure_db()