mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	updated schema
This commit is contained in:
		
							parent
							
								
									60d000b9cb
								
							
						
					
					
						commit
						eb1a6b78ff
					
				@ -1,11 +1,19 @@
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "entity_changes" (
 | 
			
		||||
                                                `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
 | 
			
		||||
                                                `entityName`	TEXT NOT NULL,
 | 
			
		||||
                                                `entityId`	TEXT NOT NULL,
 | 
			
		||||
                                                `hash`	TEXT NOT NULL,
 | 
			
		||||
                                                `isErased` INT NOT NULL,
 | 
			
		||||
                                                `sourceId` TEXT NOT NULL,
 | 
			
		||||
                                                `isSynced` INTEGER NOT NULL,
 | 
			
		||||
                                                `utcDateChanged` TEXT NOT NULL
 | 
			
		||||
                                                );
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "api_tokens"
 | 
			
		||||
(
 | 
			
		||||
    apiTokenId TEXT PRIMARY KEY NOT NULL,
 | 
			
		||||
    token TEXT NOT NULL,
 | 
			
		||||
    utcDateCreated TEXT NOT NULL,
 | 
			
		||||
  isDeleted INT NOT NULL DEFAULT 0,
 | 
			
		||||
  hash TEXT DEFAULT "" NOT NULL);
 | 
			
		||||
 | 
			
		||||
    isDeleted INT NOT NULL DEFAULT 0);
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "branches" (
 | 
			
		||||
                                          `branchId`	TEXT NOT NULL,
 | 
			
		||||
                                          `noteId`	TEXT NOT NULL,
 | 
			
		||||
@ -18,9 +26,6 @@ CREATE TABLE IF NOT EXISTS "branches" (
 | 
			
		||||
                                          `utcDateModified`	TEXT NOT NULL,
 | 
			
		||||
                                          utcDateCreated TEXT NOT NULL,
 | 
			
		||||
                                          PRIMARY KEY(`branchId`));
 | 
			
		||||
CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (`noteId`,`parentNoteId`);
 | 
			
		||||
CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId);
 | 
			
		||||
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "notes" (
 | 
			
		||||
                                       `noteId`	TEXT NOT NULL,
 | 
			
		||||
                                       `title`	TEXT NOT NULL DEFAULT "note",
 | 
			
		||||
@ -34,12 +39,6 @@ CREATE TABLE IF NOT EXISTS "notes" (
 | 
			
		||||
                                       `utcDateCreated`	TEXT NOT NULL,
 | 
			
		||||
                                       `utcDateModified`	TEXT NOT NULL,
 | 
			
		||||
                                       PRIMARY KEY(`noteId`));
 | 
			
		||||
CREATE INDEX `IDX_notes_title` ON `notes` (`title`);
 | 
			
		||||
CREATE INDEX `IDX_notes_type` ON `notes` (`type`);
 | 
			
		||||
CREATE INDEX `IDX_notes_dateCreated` ON `notes` (`dateCreated`);
 | 
			
		||||
CREATE INDEX `IDX_notes_dateModified` ON `notes` (`dateModified`);
 | 
			
		||||
CREATE INDEX `IDX_notes_utcDateModified` ON `notes` (`utcDateModified`);
 | 
			
		||||
CREATE INDEX `IDX_notes_utcDateCreated` ON `notes` (`utcDateCreated`);
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "note_contents" (
 | 
			
		||||
                                               `noteId`	TEXT NOT NULL,
 | 
			
		||||
                                               `content`	TEXT NULL DEFAULT NULL,
 | 
			
		||||
@ -58,13 +57,6 @@ CREATE TABLE IF NOT EXISTS "note_revisions" (`noteRevisionId`	TEXT NOT NULL PRIM
 | 
			
		||||
                                             `utcDateModified` TEXT NOT NULL,
 | 
			
		||||
                                             `dateLastEdited` TEXT NOT NULL,
 | 
			
		||||
                                             `dateCreated` TEXT NOT NULL);
 | 
			
		||||
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_dateCreated` ON `note_revisions` (`dateCreated`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_dateLastEdited` ON `note_revisions` (`dateLastEdited`);
 | 
			
		||||
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "note_revision_contents" (`noteRevisionId`	TEXT NOT NULL PRIMARY KEY,
 | 
			
		||||
                                                     `content`	TEXT,
 | 
			
		||||
                                                     `utcDateModified` TEXT NOT NULL);
 | 
			
		||||
@ -83,19 +75,6 @@ CREATE TABLE IF NOT EXISTS "recent_notes"
 | 
			
		||||
    utcDateCreated TEXT not null,
 | 
			
		||||
    isDeleted INT NOT NULL DEFAULT 0
 | 
			
		||||
);
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "entity_changes" (
 | 
			
		||||
                                                    `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
 | 
			
		||||
                                                    `entityName`	TEXT NOT NULL,
 | 
			
		||||
                                                    `entityId`	TEXT NOT NULL,
 | 
			
		||||
                                                    `hash`	TEXT NOT NULL,
 | 
			
		||||
                                                    `sourceId` TEXT NOT NULL,
 | 
			
		||||
                                                    `isErased` INT NOT NULL,
 | 
			
		||||
                                                    `utcDateChanged` TEXT NOT NULL,
 | 
			
		||||
                                                    `isSynced` INTEGER NOT NULL);
 | 
			
		||||
CREATE UNIQUE INDEX `IDX_entityChanges_entityName_entityId` ON "entity_changes" (
 | 
			
		||||
                                                                                 `entityName`,
 | 
			
		||||
                                                                                 `entityId`
 | 
			
		||||
    );
 | 
			
		||||
CREATE TABLE IF NOT EXISTS "attributes"
 | 
			
		||||
(
 | 
			
		||||
    attributeId      TEXT not null primary key,
 | 
			
		||||
@ -108,6 +87,23 @@ CREATE TABLE IF NOT EXISTS "attributes"
 | 
			
		||||
    isDeleted    INT  not null,
 | 
			
		||||
    `deleteId`    TEXT DEFAULT NULL,
 | 
			
		||||
    isInheritable int DEFAULT 0 NULL);
 | 
			
		||||
CREATE UNIQUE INDEX `IDX_entityChanges_entityName_entityId` ON "entity_changes" (
 | 
			
		||||
                                                                                 `entityName`,
 | 
			
		||||
                                                                                 `entityId`
 | 
			
		||||
    );
 | 
			
		||||
CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (`noteId`,`parentNoteId`);
 | 
			
		||||
CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId);
 | 
			
		||||
CREATE INDEX `IDX_notes_title` ON `notes` (`title`);
 | 
			
		||||
CREATE INDEX `IDX_notes_type` ON `notes` (`type`);
 | 
			
		||||
CREATE INDEX `IDX_notes_dateCreated` ON `notes` (`dateCreated`);
 | 
			
		||||
CREATE INDEX `IDX_notes_dateModified` ON `notes` (`dateModified`);
 | 
			
		||||
CREATE INDEX `IDX_notes_utcDateModified` ON `notes` (`utcDateModified`);
 | 
			
		||||
CREATE INDEX `IDX_notes_utcDateCreated` ON `notes` (`utcDateCreated`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_dateCreated` ON `note_revisions` (`dateCreated`);
 | 
			
		||||
CREATE INDEX `IDX_note_revisions_dateLastEdited` ON `note_revisions` (`dateLastEdited`);
 | 
			
		||||
CREATE INDEX IDX_attributes_name_value
 | 
			
		||||
    on attributes (name, value);
 | 
			
		||||
CREATE INDEX IDX_attributes_noteId_index
 | 
			
		||||
 | 
			
		||||
@ -23,9 +23,6 @@ function executeMigration(mig) {
 | 
			
		||||
        } else {
 | 
			
		||||
            throw new Error("Unknown migration type " + mig.type);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // not using repository because of changed utcDateModified column in migration 129
 | 
			
		||||
        sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -73,6 +70,9 @@ async function migrate() {
 | 
			
		||||
                executeMigration(mig);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // not using repository because of changed utcDateModified column in migration 129
 | 
			
		||||
            sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]);
 | 
			
		||||
 | 
			
		||||
            log.info("Migration to version " + mig.dbVersion + " has been successful.");
 | 
			
		||||
        }
 | 
			
		||||
        catch (e) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user