Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 76 lines (63 sloc) 2.548 kb
b51f1fc @scooby check in initial files
authored
1 import os
2
3 pragmas = """
4 PRAGMA synchronous = OFF;
5 PRAGMA journal_mode = TRUNCATE;
6 PRAGMA foreign_constraints = ON;"""
7
8 schema = """
9 CREATE TABLE IF NOT EXISTS Devices (
10 did INT NOT NULL UNIQUE,
11 uuid TEXT PRIMARY KEY,
12 node TEXT,
13 volumename TEXT);
14
15 CREATE TABLE IF NOT EXISTS Groups (
16 gid INT NOT NULL UNIQUE,
17 uuid TEXT PRIMARY KEY,
18 name TEXT,
19 realname TEXT);
20
21 CREATE TABLE IF NOT EXISTS Users (
22 uid INT NOT NULL UNIQUE,
23 uuid TEXT PRIMARY KEY,
24 name TEXT,
25 realname TEXT);
26
27 CREATE TABLE IF NOT EXISTS Inodes (
28 dev INT NOT NULL REFERENCES Devices(did) ON UPDATE CASCADE ON DELETE CASCADE,
29 inode INT NOT NULL,
30 mode INT NOT NULL,
31 uid INT NOT NULL REFERENCES Users(uid) ON UPDATE CASCADE ON DELETE CASCADE,
32 gid INT NOT NULL REFERENCES Groups(gid) ON UPDATE CASCADE ON DELETE CASCADE,
33 mtime DATETIME NOT NULL,
34 size INT NOT NULL,
35 hash TEXT,
36 PRIMARY KEY (dev, inode));
37
38 CREATE TABLE IF NOT EXISTS Paths (
39 path TEXT NOT NULL, dev TEXT NOT NULL, inode INT NOT NULL,
40 PRIMARY KEY (path), FOREIGN KEY (dev, inode) REFERENCES Inodes (dev, inode));
41
42 CREATE INDEX IF NOT EXISTS inode_Paths ON Paths (dev, inode);
43
44 CREATE VIEW IF NOT EXISTS PathNodes AS
45 SELECT path, p.dev AS dev, p.inode AS inode,
46 mode, uid, gid, mtime, size, hash
47 FROM Paths p JOIN Inodes i USING (dev, inode);
48
49 CREATE TRIGGER IF NOT EXISTS PathNodes_del INSTEAD OF
50 DELETE ON PathNodes FOR EACH ROW BEGIN
51 DELETE FROM Inodes WHERE dev = old.dev AND inode = old.inode;
52 DELETE FROM Paths WHERE dev = old.dev AND inode = old.inode;
53 END;
54
55 CREATE TRIGGER IF NOT EXISTS PathNodes_ins INSTEAD OF
56 INSERT ON PathNodes FOR EACH ROW BEGIN
57 INSERT OR REPLACE INTO Inodes (dev, inode, mode, uid, gid,
58 mtime, size, hash) VALUES (new.dev, new.inode, new.mode,
59 new.uid, new.gid, new.mtime, new.size, new.hash);
60 INSERT OR REPLACE INTO Paths (path, dev, inode)
61 VALUES (new.path, new.dev, new.inode);
62 END;
63
64 CREATE TRIGGER IF NOT EXISTS PathNodes_upd INSTEAD OF
65 UPDATE ON PathNodes FOR EACH ROW BEGIN
66 UPDATE OR REPLACE Inodes SET dev=new.dev, inode=new.inode,
67 mode=new.mode, uid=new.uid, gid=new.gid, mtime=new.mtime,
68 size=new.size, hash=new.hash
69 WHERE dev=old.dev AND inode=old.inode;
70 UPDATE OR REPLACE Paths SET dev=new.dev, inode=new.inode,
71 path=new.path
72 WHERE dev=old.dev AND inode=old.inode;
73 END;
74 """ % {'mtimetype': 'REAL' if os.stat_float_times() else 'INT'}
75
Something went wrong with that request. Please try again.