diff --git a/cloudflare-workers/schema.sql b/cloudflare-workers/schema.sql index 59039651..1743391a 100644 --- a/cloudflare-workers/schema.sql +++ b/cloudflare-workers/schema.sql @@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS `pages` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `path` TEXT UNIQUE NOT NULL ); +CREATE UNIQUE INDEX IF NOT EXISTS idx_path ON `pages`(`path`); CREATE TABLE IF NOT EXISTS `offsets` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, @@ -15,7 +16,8 @@ CREATE TABLE IF NOT EXISTS `offsets` ( `end` INTEGER NOT NULL, FOREIGN KEY(`page_id`) REFERENCES `pages`(`id`) ); -CREATE INDEX idx_offsets ON `offsets`(`start`, `end`); +CREATE INDEX IF NOT EXISTS idx_offsets ON `offsets`(`start`, `end`); +CREATE INDEX IF NOT EXISTS idx_page_id ON `offsets`(`page_id`); CREATE TABLE IF NOT EXISTS `commenters`( `id` INTEGER PRIMARY KEY AUTOINCREMENT, @@ -32,4 +34,6 @@ CREATE TABLE IF NOT EXISTS `comments` ( `created_time` TEXT NOT NULL, -- SQLite currently not support TIMESTAMP, use ISO 8601 DateTime FOREIGN KEY(`offset_id`) REFERENCES `offsets`(`id`), FOREIGN KEY(`commenter_id`) REFERENCES `commenters`(`id`) -); \ No newline at end of file +); +CREATE INDEX IF NOT EXISTS idx_offset_id ON `comments`(`offset_id`); +CREATE INDEX IF NOT EXISTS idx_commenter_id ON `comments`(`commenter_id`); \ No newline at end of file