trilium/db/schema.sql

153 lines
4.6 KiB
MySQL
Raw Normal View History

2017-12-11 11:16:20 +08:00
CREATE TABLE IF NOT EXISTS "sync" (
2018-02-01 12:36:39 +08:00
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`entityName` TEXT NOT NULL,
`entityId` TEXT NOT NULL,
`sourceId` TEXT NOT NULL,
`syncDate` TEXT NOT NULL);
2018-04-03 10:33:54 +08:00
CREATE UNIQUE INDEX `IDX_sync_entityName_entityId` ON `sync` (
`entityName`,
`entityId`
);
CREATE INDEX `IDX_sync_syncDate` ON `sync` (
`syncDate`
);
2018-02-01 12:36:39 +08:00
CREATE TABLE IF NOT EXISTS "source_ids" (
`sourceId` TEXT NOT NULL,
`dateCreated` TEXT NOT NULL,
PRIMARY KEY(`sourceId`)
2017-12-04 11:29:23 +08:00
);
2018-02-01 12:36:39 +08:00
CREATE TABLE IF NOT EXISTS "note_revisions" (
`noteRevisionId` TEXT NOT NULL PRIMARY KEY,
`noteId` TEXT NOT NULL,
`title` TEXT,
`content` TEXT,
`isProtected` INT NOT NULL DEFAULT 0,
`dateModifiedFrom` TEXT NOT NULL,
`dateModifiedTo` TEXT NOT NULL
, type TEXT DEFAULT '' NOT NULL, mime TEXT DEFAULT '' NOT NULL, hash TEXT DEFAULT "" NOT NULL);
2018-04-03 10:33:54 +08:00
CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (
`noteId`
);
CREATE INDEX `IDX_note_revisions_dateModifiedFrom` ON `note_revisions` (
`dateModifiedFrom`
);
CREATE INDEX `IDX_note_revisions_dateModifiedTo` ON `note_revisions` (
`dateModifiedTo`
2018-02-01 12:36:39 +08:00
);
CREATE TABLE IF NOT EXISTS "images"
2018-01-07 23:35:24 +08:00
(
2018-02-01 12:36:39 +08:00
imageId TEXT PRIMARY KEY NOT NULL,
2018-01-07 23:35:24 +08:00
format TEXT NOT NULL,
checksum TEXT NOT NULL,
name TEXT NOT NULL,
data BLOB,
2018-02-01 12:36:39 +08:00
isDeleted INT NOT NULL DEFAULT 0,
dateModified TEXT NOT NULL,
dateCreated TEXT NOT NULL
, hash TEXT DEFAULT "" NOT NULL);
2018-02-01 12:36:39 +08:00
CREATE TABLE note_images
2018-01-07 23:35:24 +08:00
(
2018-02-01 12:36:39 +08:00
noteImageId TEXT PRIMARY KEY NOT NULL,
noteId TEXT NOT NULL,
imageId TEXT NOT NULL,
isDeleted INT NOT NULL DEFAULT 0,
dateModified TEXT NOT NULL,
dateCreated TEXT NOT NULL
, hash TEXT DEFAULT "" NOT NULL);
2018-04-03 10:33:54 +08:00
CREATE INDEX IDX_note_images_noteId ON note_images (noteId);
CREATE INDEX IDX_note_images_imageId ON note_images (imageId);
CREATE INDEX IDX_note_images_noteId_imageId ON note_images (noteId, imageId);
CREATE TABLE IF NOT EXISTS "api_tokens"
(
2018-04-03 10:33:54 +08:00
apiTokenId TEXT PRIMARY KEY NOT NULL,
token TEXT NOT NULL,
2018-02-01 12:36:39 +08:00
dateCreated TEXT NOT NULL,
2018-04-03 10:33:54 +08:00
isDeleted INT NOT NULL DEFAULT 0
, hash TEXT DEFAULT "" NOT NULL);
2018-04-03 10:33:54 +08:00
CREATE TABLE IF NOT EXISTS "branches" (
`branchId` TEXT NOT NULL,
`noteId` TEXT NOT NULL,
`parentNoteId` TEXT NOT NULL,
`notePosition` INTEGER NOT NULL,
`prefix` TEXT,
`isExpanded` BOOLEAN,
`isDeleted` INTEGER NOT NULL DEFAULT 0,
`dateModified` TEXT NOT NULL, hash TEXT DEFAULT "" NOT NULL, dateCreated TEXT NOT NULL DEFAULT '1970-01-01T00:00:00.000Z',
2018-04-03 10:33:54 +08:00
PRIMARY KEY(`branchId`)
2018-02-01 12:36:39 +08:00
);
2018-04-03 10:33:54 +08:00
CREATE INDEX `IDX_branches_noteId` ON `branches` (
2018-02-01 12:36:39 +08:00
`noteId`
);
2018-04-03 10:33:54 +08:00
CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (
2018-02-01 12:36:39 +08:00
`noteId`,
`parentNoteId`
);
2018-04-03 10:33:54 +08:00
CREATE TABLE labels
2018-02-11 13:18:59 +08:00
(
2018-04-03 10:33:54 +08:00
labelId TEXT not null primary key,
noteId TEXT not null,
name TEXT not null,
value TEXT default '' not null,
position INT default 0 not null,
dateCreated TEXT not null,
dateModified TEXT not null,
isDeleted INT not null
, hash TEXT DEFAULT "" NOT NULL);
2018-04-03 10:33:54 +08:00
CREATE INDEX IDX_labels_name_value
on labels (name, value);
CREATE INDEX IDX_labels_noteId
on labels (noteId);
CREATE TABLE IF NOT EXISTS "notes" (
`noteId` TEXT NOT NULL,
`title` TEXT NOT NULL DEFAULT "unnamed",
`content` TEXT NOT NULL DEFAULT "",
`isProtected` INT NOT NULL DEFAULT 0,
`isDeleted` INT NOT NULL DEFAULT 0,
`dateCreated` TEXT NOT NULL,
`dateModified` TEXT NOT NULL,
type TEXT NOT NULL DEFAULT 'text',
mime TEXT NOT NULL DEFAULT 'text/html', hash TEXT DEFAULT "" NOT NULL,
PRIMARY KEY(`noteId`)
);
CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId);
CREATE INDEX IDX_notes_type
on notes (type);
CREATE TABLE IF NOT EXISTS "recent_notes" (
`branchId` TEXT NOT NULL PRIMARY KEY,
`notePath` TEXT NOT NULL,
2018-06-14 07:10:28 +08:00
hash TEXT DEFAULT "" NOT NULL,
`dateCreated` TEXT NOT NULL,
isDeleted INT
2018-06-14 07:10:28 +08:00
);
CREATE TABLE IF NOT EXISTS "event_log" (
`eventId` TEXT NOT NULL PRIMARY KEY,
`noteId` TEXT,
`comment` TEXT,
`dateCreated` TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "options"
(
2018-06-14 07:10:28 +08:00
name TEXT not null PRIMARY KEY,
value TEXT,
dateModified INT,
isSynced INTEGER default 0 not null,
hash TEXT default "" not null,
dateCreated TEXT default '1970-01-01T00:00:00.000Z' not null
);
2018-07-29 17:47:46 +08:00
CREATE TABLE relations
(
relationId TEXT not null primary key,
sourceNoteId TEXT not null,
name TEXT not null,
targetNoteId TEXT not null,
isInheritable int DEFAULT 0 NULL,
2018-07-29 17:47:46 +08:00
position INT default 0 not null,
dateCreated TEXT not null,
dateModified TEXT not null,
isDeleted INT not null
, hash TEXT DEFAULT "" NOT NULL);
CREATE INDEX IDX_relation_sourceNoteId
on relations (sourceNoteId);
CREATE INDEX IDX_relation_targetNoteId
on relations (targetNoteId);