1CREATE TABLE resources ( -- Generic table for style, source, sprite, and glyph resources. 2 id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 3 url TEXT NOT NULL, 4 kind INTEGER NOT NULL, 5 expires INTEGER, 6 modified INTEGER, 7 etag TEXT, 8 data BLOB, 9 compressed INTEGER NOT NULL DEFAULT 0, 10 accessed INTEGER NOT NULL, 11 must_revalidate INTEGER NOT NULL DEFAULT 0, 12 UNIQUE (url) 13); 14 15CREATE TABLE tiles ( 16 id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 17 url_template TEXT NOT NULL, 18 pixel_ratio INTEGER NOT NULL, 19 z INTEGER NOT NULL, 20 x INTEGER NOT NULL, 21 y INTEGER NOT NULL, 22 expires INTEGER, 23 modified INTEGER, 24 etag TEXT, 25 data BLOB, 26 compressed INTEGER NOT NULL DEFAULT 0, 27 accessed INTEGER NOT NULL, 28 must_revalidate INTEGER NOT NULL DEFAULT 0, 29 UNIQUE (url_template, pixel_ratio, z, x, y) 30); 31 32CREATE TABLE regions ( 33 id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 34 definition TEXT NOT NULL, -- JSON formatted definition of region. Regions may be of variant types: 35 -- e.g. bbox and zoom range, route path, flyTo parameters, etc. Note that 36 -- the set of tiles required for a region may span multiple sources. 37 description BLOB -- User provided data in user-defined format 38); 39 40CREATE TABLE region_resources ( 41 region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE, 42 resource_id INTEGER NOT NULL REFERENCES resources(id), 43 UNIQUE (region_id, resource_id) 44); 45 46CREATE TABLE region_tiles ( 47 region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE, 48 tile_id INTEGER NOT NULL REFERENCES tiles(id), 49 UNIQUE (region_id, tile_id) 50); 51 52-- Indexes for efficient eviction queries 53 54CREATE INDEX resources_accessed 55ON resources (accessed); 56 57CREATE INDEX tiles_accessed 58ON tiles (accessed); 59 60CREATE INDEX region_resources_resource_id 61ON region_resources (resource_id); 62 63CREATE INDEX region_tiles_tile_id 64ON region_tiles (tile_id); 65