Skip to content

Commit

Permalink
refactor(workers): add foreign key index
Browse files Browse the repository at this point in the history
  • Loading branch information
shaokeyibb authored and Enter-tainer committed Jul 18, 2024
1 parent 370c1c8 commit 773571a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cloudflare-workers/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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`)
);
);
CREATE INDEX IF NOT EXISTS idx_offset_id ON `comments`(`offset_id`);
CREATE INDEX IF NOT EXISTS idx_commenter_id ON `comments`(`commenter_id`);

0 comments on commit 773571a

Please sign in to comment.