summaryrefslogtreecommitdiff
path: root/platform/default/mbgl/storage/offline_schema.sql
blob: ecb7b6d95201d1f374962bd0b3f72da4966b104e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
CREATE TABLE resources (                   -- Generic table for style, source, sprite, and glyph resources.
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  url TEXT NOT NULL,
  kind INTEGER NOT NULL,
  expires INTEGER,
  modified INTEGER,
  etag TEXT,
  data BLOB,
  compressed INTEGER NOT NULL DEFAULT 0,
  accessed INTEGER NOT NULL,
  UNIQUE (url)
);

CREATE TABLE tilesets (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  url_template TEXT NOT NULL,           -- As it would appear in TileJSON (but no support for host sharding).
  pixel_ratio INTEGER,                  -- If NULL, 1 is assumed for raster sources.
  UNIQUE (url_template, pixel_ratio)    -- Capable of caching the same tileset at multiple resolutions.
);

CREATE TABLE tiles (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  tileset_id INTEGER NOT NULL REFERENCES tilesets(id),
  z INTEGER NOT NULL,
  x INTEGER NOT NULL,
  y INTEGER NOT NULL,
  expires INTEGER,
  modified INTEGER,
  etag TEXT,
  data BLOB,
  compressed INTEGER NOT NULL DEFAULT 0,
  accessed INTEGER NOT NULL,
  UNIQUE (tileset_id, z, x, y)
);

CREATE TABLE regions (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  definition TEXT NOT NULL,   -- JSON formatted definition of region. Regions may be of variant types:
                              -- e.g. bbox and zoom range, route path, flyTo parameters, etc. Note that
                              -- the set of tiles required for a region may span multiple sources.
  description BLOB            -- User provided data in user-defined format
);

CREATE TABLE region_resources (
  region_id INTEGER NOT NULL REFERENCES regions(id),
  resource_id INTEGER NOT NULL REFERENCES resources(id),
  UNIQUE (region_id, resource_id)
);

CREATE TABLE region_tiles (
  region_id INTEGER NOT NULL REFERENCES regions(id),
  tile_id INTEGER NOT NULL REFERENCES tiles(id),
  UNIQUE (region_id, tile_id)
);

-- Indexes for efficient eviction queries

CREATE INDEX resources_accessed
ON resources (accessed);

CREATE INDEX tiles_accessed
ON tiles (accessed);

CREATE INDEX region_resources_resource_id
ON region_resources (resource_id);

CREATE INDEX region_tiles_tile_id
ON region_tiles (tile_id);