schema.sql 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. CREATE TABLE IF NOT EXISTS "api_tokens"
  2. (
  3. apiTokenId TEXT PRIMARY KEY NOT NULL,
  4. token TEXT NOT NULL,
  5. utcDateCreated TEXT NOT NULL,
  6. isDeleted INT NOT NULL DEFAULT 0,
  7. hash TEXT DEFAULT "" NOT NULL);
  8. CREATE TABLE IF NOT EXISTS "options"
  9. (
  10. name TEXT not null PRIMARY KEY,
  11. value TEXT,
  12. isSynced INTEGER default 0 not null,
  13. hash TEXT default "" not null,
  14. utcDateCreated TEXT not null,
  15. utcDateModified TEXT NOT NULL
  16. );
  17. CREATE TABLE recent_notes
  18. (
  19. noteId TEXT not null primary key,
  20. notePath TEXT not null,
  21. hash TEXT default "" not null,
  22. utcDateCreated TEXT not null,
  23. isDeleted INT
  24. );
  25. CREATE TABLE IF NOT EXISTS "note_revision_contents" (`noteRevisionId` TEXT NOT NULL PRIMARY KEY,
  26. `content` TEXT,
  27. hash TEXT DEFAULT '' NOT NULL,
  28. `utcDateModified` TEXT NOT NULL);
  29. CREATE TABLE IF NOT EXISTS "branches" (
  30. `branchId` TEXT NOT NULL,
  31. `noteId` TEXT NOT NULL,
  32. `parentNoteId` TEXT NOT NULL,
  33. `notePosition` INTEGER NOT NULL,
  34. `prefix` TEXT,
  35. `isExpanded` INTEGER NOT NULL DEFAULT 0,
  36. `isDeleted` INTEGER NOT NULL DEFAULT 0,
  37. `deleteId` TEXT DEFAULT NULL,
  38. `utcDateModified` TEXT NOT NULL,
  39. utcDateCreated TEXT NOT NULL,
  40. hash TEXT DEFAULT "" NOT NULL,
  41. PRIMARY KEY(`branchId`));
  42. CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (`noteId`,`parentNoteId`);
  43. CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId);
  44. CREATE TABLE IF NOT EXISTS "attributes"
  45. (
  46. attributeId TEXT not null primary key,
  47. noteId TEXT not null,
  48. type TEXT not null,
  49. name TEXT not null,
  50. value TEXT default '' not null,
  51. position INT default 0 not null,
  52. utcDateCreated TEXT not null,
  53. utcDateModified TEXT not null,
  54. isDeleted INT not null,
  55. `deleteId` TEXT DEFAULT NULL,
  56. hash TEXT default "" not null,
  57. isInheritable int DEFAULT 0 NULL);
  58. CREATE INDEX IDX_attributes_name_value
  59. on attributes (name, value);
  60. CREATE INDEX IDX_attributes_noteId_index
  61. on attributes (noteId);
  62. CREATE INDEX IDX_attributes_value_index
  63. on attributes (value);
  64. CREATE TABLE IF NOT EXISTS "entity_changes" (
  65. `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  66. `entityName` TEXT NOT NULL,
  67. `entityId` TEXT NOT NULL,
  68. `sourceId` TEXT NOT NULL,
  69. `isSynced` INTEGER default 0 not null,
  70. `utcChangedDate` TEXT NOT NULL);
  71. CREATE UNIQUE INDEX `IDX_entityChanges_entityName_entityId` ON "entity_changes" (
  72. `entityName`,
  73. `entityId`
  74. );
  75. CREATE INDEX `IDX_entityChanges_utcChangedDate` ON "entity_changes" (
  76. `utcChangedDate`
  77. );
  78. CREATE TABLE IF NOT EXISTS "notes" (
  79. `noteId` TEXT NOT NULL,
  80. `title` TEXT NOT NULL DEFAULT "note",
  81. `isProtected` INT NOT NULL DEFAULT 0,
  82. `type` TEXT NOT NULL DEFAULT 'text',
  83. `mime` TEXT NOT NULL DEFAULT 'text/html',
  84. `hash` TEXT DEFAULT "" NOT NULL,
  85. `isDeleted` INT NOT NULL DEFAULT 0,
  86. `deleteId` TEXT DEFAULT NULL,
  87. `isErased` INT NOT NULL DEFAULT 0,
  88. `dateCreated` TEXT NOT NULL,
  89. `dateModified` TEXT NOT NULL,
  90. `utcDateCreated` TEXT NOT NULL,
  91. `utcDateModified` TEXT NOT NULL,
  92. PRIMARY KEY(`noteId`));
  93. CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`);
  94. CREATE INDEX `IDX_notes_title` ON `notes` (`title`);
  95. CREATE INDEX `IDX_notes_type` ON `notes` (`type`);
  96. CREATE INDEX `IDX_notes_dateCreated` ON `notes` (`dateCreated`);
  97. CREATE INDEX `IDX_notes_dateModified` ON `notes` (`dateModified`);
  98. CREATE INDEX `IDX_notes_utcDateModified` ON `notes` (`utcDateModified`);
  99. CREATE INDEX `IDX_notes_utcDateCreated` ON `notes` (`utcDateCreated`);
  100. CREATE TABLE IF NOT EXISTS "note_revisions" (`noteRevisionId` TEXT NOT NULL PRIMARY KEY,
  101. `noteId` TEXT NOT NULL,
  102. `title` TEXT,
  103. `isErased` INT NOT NULL DEFAULT 0,
  104. `isProtected` INT NOT NULL DEFAULT 0,
  105. `utcDateLastEdited` TEXT NOT NULL,
  106. `utcDateCreated` TEXT NOT NULL,
  107. `utcDateModified` TEXT NOT NULL,
  108. `dateLastEdited` TEXT NOT NULL,
  109. `dateCreated` TEXT NOT NULL,
  110. type TEXT DEFAULT '' NOT NULL,
  111. mime TEXT DEFAULT '' NOT NULL,
  112. hash TEXT DEFAULT '' NOT NULL);
  113. CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`);
  114. CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`);
  115. CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`);
  116. CREATE INDEX `IDX_note_revisions_dateCreated` ON `note_revisions` (`dateCreated`);
  117. CREATE INDEX `IDX_note_revisions_dateLastEdited` ON `note_revisions` (`dateLastEdited`);
  118. CREATE TABLE IF NOT EXISTS "note_contents" (
  119. `noteId` TEXT NOT NULL,
  120. `content` TEXT NULL DEFAULT NULL,
  121. `hash` TEXT DEFAULT "" NOT NULL,
  122. `dateModified` TEXT NOT NULL,
  123. `utcDateModified` TEXT NOT NULL,
  124. PRIMARY KEY(`noteId`)
  125. );