* Under the hood, SQLite creates surrogate keys (ROWID) anyway. We may as well take advantage of this and use the surrogates for foreign keys as well, since they are simpler and more efficient than compound foreign keys. * Create indexes for efficient eviction queries
58 lines
1.8 KiB
Plaintext
58 lines
1.8 KiB
Plaintext
/* THIS IS A GENERATED FILE; EDIT offline_schema.sql INSTEAD */
|
|
static const char * schema =
|
|
"CREATE TABLE resources (\n"
|
|
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
|
" url TEXT NOT NULL UNIQUE,\n"
|
|
" kind INTEGER NOT NULL,\n"
|
|
" expires INTEGER,\n"
|
|
" modified INTEGER,\n"
|
|
" etag TEXT,\n"
|
|
" data BLOB,\n"
|
|
" compressed INTEGER NOT NULL DEFAULT 0,\n"
|
|
" accessed INTEGER NOT NULL\n"
|
|
");\n"
|
|
"CREATE TABLE tilesets (\n"
|
|
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
|
" url_template TEXT NOT NULL,\n"
|
|
" pixel_ratio INTEGER,\n"
|
|
" UNIQUE (url_template, pixel_ratio)\n"
|
|
");\n"
|
|
"CREATE TABLE tiles (\n"
|
|
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
|
" tileset_id INTEGER NOT NULL REFERENCES tilesets(id),\n"
|
|
" z INTEGER NOT NULL,\n"
|
|
" x INTEGER NOT NULL,\n"
|
|
" y INTEGER NOT NULL,\n"
|
|
" expires INTEGER,\n"
|
|
" modified INTEGER,\n"
|
|
" etag TEXT,\n"
|
|
" data BLOB,\n"
|
|
" compressed INTEGER NOT NULL DEFAULT 0,\n"
|
|
" accessed INTEGER NOT NULL,\n"
|
|
" UNIQUE (tileset_id, z, x, y)\n"
|
|
");\n"
|
|
"CREATE TABLE regions (\n"
|
|
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
|
" definition TEXT NOT NULL,\n"
|
|
" description BLOB\n"
|
|
");\n"
|
|
"CREATE TABLE region_resources (\n"
|
|
" region_id INTEGER NOT NULL REFERENCES regions(id),\n"
|
|
" resource_id INTEGER NOT NULL REFERENCES resources(id),\n"
|
|
" UNIQUE (region_id, resource_id)\n"
|
|
");\n"
|
|
"CREATE TABLE region_tiles (\n"
|
|
" region_id INTEGER NOT NULL REFERENCES regions(id),\n"
|
|
" tile_id INTEGER NOT NULL REFERENCES tiles(id),\n"
|
|
" UNIQUE (region_id, tile_id)\n"
|
|
");\n"
|
|
"CREATE INDEX resources_accessed\n"
|
|
"ON resources (accessed);\n"
|
|
"CREATE INDEX tiles_accessed\n"
|
|
"ON tiles (accessed);\n"
|
|
"CREATE INDEX region_resources_resource_id\n"
|
|
"ON region_resources (resource_id);\n"
|
|
"CREATE INDEX region_tiles_tile_id\n"
|
|
"ON region_tiles (tile_id);\n"
|
|
;
|