mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	removed older migrations since they don't work anyway (after becca refactoring)
This commit is contained in:
		
							parent
							
								
									b041d081db
								
							
						
					
					
						commit
						fd00f6bd97
					
				| @ -1,5 +0,0 @@ | |||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
| VALUES ('leftPaneMinWidth', '350', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
| VALUES ('leftPaneWidthPercent', '20', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1 +0,0 @@ | |||||||
| update branches set parentNoteId = 'none' where branchId = 'root' |  | ||||||
| @ -1,75 +0,0 @@ | |||||||
| -- first fix deleted status of existing images |  | ||||||
| UPDATE note_images SET isDeleted = 1 WHERE noteId IN (SELECT noteId FROM notes WHERE isDeleted = 1); |  | ||||||
| 
 |  | ||||||
| -- we don't need set data to null because table is going to be dropped anyway and we want image size into attribute |  | ||||||
| UPDATE images SET isDeleted = 1 WHERE imageId NOT IN (SELECT imageId FROM note_images WHERE isDeleted = 0); |  | ||||||
| 
 |  | ||||||
| -- allow null for note content (for deleted notes) |  | ||||||
| CREATE TABLE IF NOT EXISTS "notes_mig" ( |  | ||||||
|   `noteId`	TEXT NOT NULL, |  | ||||||
|   `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|   `content`	TEXT NULL DEFAULT NULL, |  | ||||||
|   `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|   `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|   `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|   `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|   `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|   `dateCreated`	TEXT NOT NULL, |  | ||||||
|   `dateModified`	TEXT NOT NULL, |  | ||||||
|   PRIMARY KEY(`noteId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes_mig (noteId, title, content, isProtected, isDeleted, dateCreated, dateModified, type, mime, hash) |  | ||||||
| SELECT noteId, title, content, isProtected, isDeleted, dateCreated, dateModified, type, mime, hash FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| 
 |  | ||||||
| ALTER TABLE notes_mig RENAME TO notes; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE "links" ( |  | ||||||
|   `linkId`	TEXT NOT NULL, |  | ||||||
|   `noteId`	TEXT NOT NULL, |  | ||||||
|   `targetNoteId`	TEXT NOT NULL, |  | ||||||
|   `type` TEXT NOT NULL, |  | ||||||
|   `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|   `isDeleted`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|   `dateCreated`	TEXT NOT NULL, |  | ||||||
|   `dateModified`	TEXT NOT NULL, |  | ||||||
|   PRIMARY KEY(`linkId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO links (linkId, noteId, targetNoteId, type, isDeleted, dateCreated, dateModified) |  | ||||||
|   SELECT 'L' || SUBSTR(noteImageId, 2), noteId, imageId, 'image', isDeleted, dateCreated, dateModified FROM note_images; |  | ||||||
| 
 |  | ||||||
| INSERT INTO branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, dateModified, hash, dateCreated) |  | ||||||
|   SELECT 'B' || SUBSTR(noteImageId, 2), imageId, noteId, 100, '', 0, isDeleted, dateModified, hash, dateCreated FROM note_images; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_images; |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes (noteId, title, content, isProtected, isDeleted, dateCreated, dateModified, type, mime, hash) |  | ||||||
|   SELECT imageId, name, data, 0, isDeleted, dateCreated, dateModified, 'image', 'image/' || format, hash FROM images; |  | ||||||
| 
 |  | ||||||
| INSERT INTO attributes (attributeId, noteId, type, name, value, position, dateCreated, dateModified, isDeleted, hash, isInheritable) |  | ||||||
|   SELECT 'O' || SUBSTR(imageId, 2), imageId, 'label', 'originalFileName', name, 0, dateCreated, dateModified, isDeleted, '', 0 FROM images; |  | ||||||
| 
 |  | ||||||
| INSERT INTO attributes (attributeId, noteId, type, name, value, position, dateCreated, dateModified, isDeleted, hash, isInheritable) |  | ||||||
| SELECT 'F' || SUBSTR(imageId, 2), imageId, 'label', 'fileSize', LENGTH(data), 0, dateCreated, dateModified, isDeleted, '', 0 FROM images; |  | ||||||
| 
 |  | ||||||
| DROP TABLE images; |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync (entityName, entityId, sourceId, syncDate) |  | ||||||
| SELECT 'attributes', 'O' || SUBSTR(entityId, 2), sourceId, syncDate FROM sync WHERE entityName = 'images'; |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync (entityName, entityId, sourceId, syncDate) |  | ||||||
| SELECT 'attributes', 'F' || SUBSTR(entityId, 2), sourceId, syncDate FROM sync WHERE entityName = 'images'; |  | ||||||
| 
 |  | ||||||
| UPDATE sync SET entityName = 'notes' WHERE entityName = 'images'; |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync (entityName, entityId, sourceId, syncDate) |  | ||||||
| SELECT 'links', 'L' || SUBSTR(entityId, 2), sourceId, syncDate FROM sync WHERE entityName = 'note_images'; |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync (entityName, entityId, sourceId, syncDate) |  | ||||||
|   SELECT 'branches', 'B' || SUBSTR(entityId, 2), sourceId, syncDate FROM sync WHERE entityName = 'note_images'; |  | ||||||
| 
 |  | ||||||
| DELETE FROM sync WHERE entityName = 'note_images'; |  | ||||||
| DELETE FROM sync WHERE entityName = 'images'; |  | ||||||
| @ -1,14 +0,0 @@ | |||||||
| create index IDX_links_noteId_index |  | ||||||
|   on links (noteId); |  | ||||||
| 
 |  | ||||||
| create index IDX_links_targetNoteId_index |  | ||||||
|   on links (targetNoteId); |  | ||||||
| 
 |  | ||||||
| create index IDX_attributes_name_index |  | ||||||
|   on attributes (name); |  | ||||||
| 
 |  | ||||||
| create index IDX_attributes_noteId_index |  | ||||||
|   on attributes (noteId); |  | ||||||
| 
 |  | ||||||
| create index IDX_attributes_value_index |  | ||||||
|   on attributes (value); |  | ||||||
| @ -1 +0,0 @@ | |||||||
| UPDATE attributes SET isDeleted = 1 WHERE noteId IN (SELECT noteId FROM notes WHERE isDeleted = 1); |  | ||||||
| @ -1 +0,0 @@ | |||||||
| UPDATE attributes SET isDeleted = 1 WHERE type = 'relation' AND value NOT IN (SELECT noteId FROM notes WHERE notes.isDeleted = 0); |  | ||||||
| @ -1 +0,0 @@ | |||||||
| UPDATE attributes SET value = replace(value, 'mirrorRelation', 'inverseRelation') WHERE type = 'relation-definition'; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| UPDATE attributes SET name = 'archived' where name = 'hideInAutocomplete'; |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
| VALUES ('hoistedNoteId', 'root', '2018-12-11T18:31:00.874Z', '2018-12-11T18:31:00.874Z', 0); |  | ||||||
| @ -1,62 +0,0 @@ | |||||||
| const sql = require('../../src/services/sql'); |  | ||||||
| 
 |  | ||||||
| function prependIv(cipherText, ivText) { |  | ||||||
|     const arr = ivText.split("").map(c => parseInt(c) || 0); |  | ||||||
|     const iv = Buffer.from(arr); |  | ||||||
|     const payload = Buffer.from(cipherText, 'base64'); |  | ||||||
|     const complete = Buffer.concat([iv, payload]); |  | ||||||
| 
 |  | ||||||
|     return complete.toString('base64'); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| async function updateEncryptedDataKey() { |  | ||||||
|     const encryptedDataKey = await sql.getValue("SELECT value FROM options WHERE name = 'encryptedDataKey'"); |  | ||||||
|     const encryptedDataKeyIv = await sql.getValue("SELECT value FROM options WHERE name = 'encryptedDataKeyIv'"); |  | ||||||
| 
 |  | ||||||
|     const newEncryptedDataKey = prependIv(encryptedDataKey, encryptedDataKeyIv); |  | ||||||
| 
 |  | ||||||
|     await sql.execute("UPDATE options SET value = ? WHERE name = 'encryptedDataKey'", [newEncryptedDataKey]); |  | ||||||
| 
 |  | ||||||
|     await sql.execute("DELETE FROM options WHERE name = 'encryptedDataKeyIv'"); |  | ||||||
|     await sql.execute("DELETE FROM sync WHERE entityName = 'options' AND entityId = 'encryptedDataKeyIv'"); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| async function updateNotes() { |  | ||||||
|     const protectedNotes = await sql.getRows("SELECT noteId, title, content FROM notes WHERE isProtected = 1"); |  | ||||||
| 
 |  | ||||||
|     for (const note of protectedNotes) { |  | ||||||
|         if (note.title !== null) { |  | ||||||
|             note.title = prependIv(note.title, "0" + note.noteId); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (note.content !== null) { |  | ||||||
|             note.content = prependIv(note.content, "1" + note.noteId); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         await sql.execute("UPDATE notes SET title = ?, content = ? WHERE noteId = ?", [note.title, note.content, note.noteId]); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| async function updateNoteRevisions() { |  | ||||||
|     const protectedNoteRevisions = await sql.getRows("SELECT noteRevisionId, title, content FROM note_revisions WHERE isProtected = 1"); |  | ||||||
| 
 |  | ||||||
|     for (const noteRevision of protectedNoteRevisions) { |  | ||||||
|         if (noteRevision.title !== null) { |  | ||||||
|             noteRevision.title = prependIv(noteRevision.title, "0" + noteRevision.noteRevisionId); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (noteRevision.content !== null) { |  | ||||||
|             noteRevision.content = prependIv(noteRevision.content, "1" + noteRevision.noteRevisionId); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         await sql.execute("UPDATE note_revisions SET title = ?, content = ? WHERE noteRevisionId = ?", [noteRevision.title, noteRevision.content, noteRevision.noteRevisionId]); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| module.exports = async () => { |  | ||||||
|     await updateEncryptedDataKey(); |  | ||||||
| 
 |  | ||||||
|     await updateNotes(); |  | ||||||
| 
 |  | ||||||
|     await updateNoteRevisions(); |  | ||||||
| }; |  | ||||||
| @ -1,8 +0,0 @@ | |||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
| VALUES ('mainFontSize', '100', '2019-01-13T18:31:00.874Z', '2019-01-13T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
| VALUES ('treeFontSize', '100', '2019-01-13T18:31:00.874Z', '2019-01-13T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
| VALUES ('detailFontSize', '110', '2019-01-13T18:31:00.874Z', '2019-01-13T18:31:00.874Z', 0); |  | ||||||
| @ -1,11 +0,0 @@ | |||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
|   SELECT 'mainFontSize', '100', '2019-01-13T18:31:00.874Z', '2019-01-13T18:31:00.874Z', 0 |  | ||||||
|     WHERE NOT EXISTS (SELECT 1 FROM options WHERE name = 'mainFontSize'); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
|   SELECT 'treeFontSize', '100', '2019-01-13T18:31:00.874Z', '2019-01-13T18:31:00.874Z', 0 |  | ||||||
|     WHERE NOT EXISTS (SELECT 1 FROM options WHERE name = 'treeFontSize'); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, dateCreated, dateModified, isSynced) |  | ||||||
|   SELECT 'detailFontSize', '110', '2019-01-13T18:31:00.874Z', '2019-01-13T18:31:00.874Z', 0 |  | ||||||
|     WHERE NOT EXISTS (SELECT 1 FROM options WHERE name = 'detailFontSize'); |  | ||||||
| @ -1,35 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "note_contents" ( |  | ||||||
|   `noteContentId`	TEXT NOT NULL, |  | ||||||
|   `noteId`	TEXT NOT NULL, |  | ||||||
|   `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|   `content`	TEXT NULL DEFAULT NULL, |  | ||||||
|   `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|   `dateCreated`	TEXT NOT NULL, |  | ||||||
|   `dateModified` TEXT NOT NULL, |  | ||||||
|   PRIMARY KEY(`noteContentId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| CREATE UNIQUE INDEX `IDX_note_contents_noteId` ON `note_contents` (`noteId`); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_contents (noteContentId, noteId, isProtected, content, dateCreated, dateModified) |  | ||||||
|   SELECT 'C' || SUBSTR(noteId, 2), noteId, isProtected, content, dateCreated, dateModified FROM notes; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "notes_mig" ( |  | ||||||
|   `noteId`	TEXT NOT NULL, |  | ||||||
|   `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|   `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|   `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|   `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|   `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|   `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|   `dateCreated`	TEXT NOT NULL, |  | ||||||
|   `dateModified`	TEXT NOT NULL, |  | ||||||
|   PRIMARY KEY(`noteId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes_mig (noteId, title, isProtected, isDeleted, dateCreated, dateModified, type, mime, hash) |  | ||||||
| SELECT noteId, title, isProtected, isDeleted, dateCreated, dateModified, type, mime, hash FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| 
 |  | ||||||
| ALTER TABLE notes_mig RENAME TO notes; |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| INSERT OR REPLACE INTO sync (entityName, entityId, sourceId, syncDate) |  | ||||||
| SELECT 'note_contents', noteContentId, '', '2019-03-02T18:07:29.182Z' FROM note_contents; |  | ||||||
| @ -1,6 +0,0 @@ | |||||||
| UPDATE notes SET title = 'Recovered protected note', isProtected = 0 WHERE noteId IN ( |  | ||||||
|     SELECT noteId FROM notes JOIN note_contents USING(noteId) |  | ||||||
|     WHERE notes.isProtected = 1 |  | ||||||
|       AND note_contents.isProtected = 0 |  | ||||||
|       AND notes.isDeleted = 0 |  | ||||||
| ) |  | ||||||
| @ -1 +0,0 @@ | |||||||
| module.exports = async () => {}; |  | ||||||
| @ -1,236 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "sync_mig" ( |  | ||||||
|                                     `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |  | ||||||
|                                     `entityName`	TEXT NOT NULL, |  | ||||||
|                                     `entityId`	TEXT NOT NULL, |  | ||||||
|                                     `sourceId` TEXT NOT NULL, |  | ||||||
|                                     `utcSyncDate`	TEXT NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync_mig (id, entityName, entityId, sourceId, utcSyncDate) |  | ||||||
|   SELECT id, entityName, entityId, sourceId, REPLACE(syncDate, 'T', ' ') FROM sync; |  | ||||||
| 
 |  | ||||||
| DROP TABLE sync; |  | ||||||
| ALTER TABLE sync_mig RENAME TO sync; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "source_ids_mig" ( |  | ||||||
|                                           `sourceId`	TEXT NOT NULL, |  | ||||||
|                                           `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                           PRIMARY KEY(`sourceId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO source_ids_mig (sourceId, utcDateCreated) |  | ||||||
|   SELECT sourceId, REPLACE(dateCreated, 'T', ' ') FROM source_ids; |  | ||||||
| 
 |  | ||||||
| DROP TABLE source_ids; |  | ||||||
| ALTER TABLE source_ids_mig RENAME TO source_ids; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "note_revisions_mig" ( |  | ||||||
|                                               `noteRevisionId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                               `noteId`	TEXT NOT NULL, |  | ||||||
|                                               `title`	TEXT, |  | ||||||
|                                               `content`	TEXT, |  | ||||||
|                                               `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                               `utcDateModifiedFrom` TEXT NOT NULL, |  | ||||||
|                                               `utcDateModifiedTo` TEXT NOT NULL, |  | ||||||
|                                               `dateModifiedFrom` TEXT NOT NULL, |  | ||||||
|                                               `dateModifiedTo` TEXT NOT NULL, |  | ||||||
|                                               type TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                               mime TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                               hash TEXT DEFAULT "" NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_revisions_mig (noteRevisionId, noteId, title, content, isProtected, utcDateModifiedFrom, utcDateModifiedTo, dateModifiedFrom, dateModifiedTo, type, mime, hash) |  | ||||||
| SELECT noteRevisionId, noteId, title, content, isProtected, REPLACE(dateModifiedFrom, 'T', ' '), REPLACE(dateModifiedTo, 'T', ' '), REPLACE(REPLACE(dateModifiedFrom, 'T', ' '), 'Z', '+0000'), REPLACE(REPLACE(dateModifiedTo, 'T', ' '), 'Z', '+0000'), type, mime, hash FROM note_revisions; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_revisions; |  | ||||||
| ALTER TABLE note_revisions_mig RENAME TO note_revisions; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "api_tokens_mig" |  | ||||||
| ( |  | ||||||
|   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); |  | ||||||
| 
 |  | ||||||
| INSERT INTO api_tokens_mig (apiTokenId, token, utcDateCreated, isDeleted, hash) |  | ||||||
|   SELECT apiTokenId, token, REPLACE(dateCreated, 'T', ' '), isDeleted, hash FROM api_tokens; |  | ||||||
| 
 |  | ||||||
| DROP TABLE api_tokens; |  | ||||||
| ALTER TABLE api_tokens_mig RENAME TO api_tokens; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "branches_mig" ( |  | ||||||
|                                         `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, |  | ||||||
|                                         `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                         utcDateCreated TEXT NOT NULL, |  | ||||||
|                                         hash TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                         PRIMARY KEY(`branchId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO branches_mig (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, utcDateModified, utcDateCreated, hash) |  | ||||||
|   SELECT branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, REPLACE(dateModified, 'T', ' '), REPLACE(dateCreated, 'T', ' '), hash FROM branches; |  | ||||||
| 
 |  | ||||||
| DROP TABLE branches; |  | ||||||
| ALTER TABLE branches_mig RENAME TO branches; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "recent_notes_mig" ( |  | ||||||
|                                             `branchId` TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                             `notePath` TEXT NOT NULL, |  | ||||||
|                                             hash TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                             `utcDateCreated` TEXT NOT NULL, |  | ||||||
|                                             isDeleted INT |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO recent_notes_mig (branchId, notePath, hash, utcDateCreated, isDeleted) |  | ||||||
|   SELECT branchId, notePath, hash, REPLACE(dateCreated, 'T', ' '), isDeleted FROM recent_notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE recent_notes; |  | ||||||
| ALTER TABLE recent_notes_mig RENAME TO recent_notes; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "event_log_mig" ( |  | ||||||
|                                          `eventId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                          `noteId`	TEXT, |  | ||||||
|                                          `comment`	TEXT, |  | ||||||
|                                          `utcDateCreated`	TEXT NOT NULL |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO event_log_mig (eventId, noteId, comment, utcDateCreated) |  | ||||||
|   SELECT eventId, noteId, comment, REPLACE(dateCreated, 'T', ' ') FROM event_log; |  | ||||||
| 
 |  | ||||||
| DROP TABLE event_log; |  | ||||||
| ALTER TABLE event_log_mig RENAME TO event_log; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "options_mig" |  | ||||||
| ( |  | ||||||
|   name TEXT not null PRIMARY KEY, |  | ||||||
|   value TEXT, |  | ||||||
|   isSynced INTEGER default 0 not null, |  | ||||||
|   hash TEXT default "" not null, |  | ||||||
|   utcDateCreated TEXT not null, |  | ||||||
|   utcDateModified TEXT NOT NULL |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options_mig (name, value, isSynced, hash, utcDateCreated, utcDateModified) |  | ||||||
|   SELECT name, value, isSynced, hash, REPLACE(dateCreated, 'T', ' '), REPLACE(dateModified, 'T', ' ') FROM options; |  | ||||||
| 
 |  | ||||||
| DROP TABLE options; |  | ||||||
| ALTER TABLE options_mig RENAME TO options; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE attributes_mig |  | ||||||
| ( |  | ||||||
|   attributeId      TEXT not null primary key, |  | ||||||
|   noteId       TEXT not null, |  | ||||||
|   type         TEXT not null, |  | ||||||
|   name         TEXT not null, |  | ||||||
|   value        TEXT default '' not null, |  | ||||||
|   position     INT  default 0 not null, |  | ||||||
|   utcDateCreated  TEXT not null, |  | ||||||
|   utcDateModified TEXT not null, |  | ||||||
|   isDeleted    INT  not null, |  | ||||||
|   hash         TEXT default "" not null, |  | ||||||
|   isInheritable int DEFAULT 0 NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO attributes_mig (attributeId, noteId, type, name, value, position, utcDateCreated, utcDateModified, isDeleted, hash, isInheritable) |  | ||||||
|   SELECT attributeId, noteId, type, name, value, position, REPLACE(dateCreated, 'T', ' '), REPLACE(dateModified, 'T', ' '), isDeleted, hash, isInheritable FROM attributes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE attributes; |  | ||||||
| ALTER TABLE attributes_mig RENAME TO attributes; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "links_mig" ( |  | ||||||
|                                      `linkId`	TEXT NOT NULL, |  | ||||||
|                                      `noteId`	TEXT NOT NULL, |  | ||||||
|                                      `targetNoteId`	TEXT NOT NULL, |  | ||||||
|                                      `type` TEXT NOT NULL, |  | ||||||
|                                      `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                      `isDeleted`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|                                      `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                      `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                      PRIMARY KEY(`linkId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO links_mig (linkId, noteId, targetNoteId, type, hash, isDeleted, utcDateCreated, utcDateModified) |  | ||||||
|   SELECT linkId, noteId, targetNoteId, type, hash, isDeleted, REPLACE(dateCreated, 'T', ' '), REPLACE(dateModified, 'T', ' ') FROM links; |  | ||||||
| 
 |  | ||||||
| DROP TABLE links; |  | ||||||
| ALTER TABLE links_mig RENAME TO links; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "note_contents_mig" ( |  | ||||||
|                                              `noteContentId`	TEXT NOT NULL, |  | ||||||
|                                              `noteId`	TEXT NOT NULL, |  | ||||||
|                                              `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                              `content`	TEXT NULL DEFAULT NULL, |  | ||||||
|                                              `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                              `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                              `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                              PRIMARY KEY(`noteContentId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_contents_mig (noteContentId, noteId, isProtected, content, hash, utcDateCreated, utcDateModified) |  | ||||||
|   SELECT noteContentId, noteId, isProtected, content, hash, REPLACE(dateCreated, 'T', ' '), REPLACE(dateModified, 'T', ' ') FROM note_contents; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_contents; |  | ||||||
| ALTER TABLE note_contents_mig RENAME TO note_contents; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "notes_mig" ( |  | ||||||
|                                      `noteId`	TEXT NOT NULL, |  | ||||||
|                                      `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|                                      `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                      `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|                                      `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|                                      `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                      `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                      `dateCreated`	TEXT NOT NULL, |  | ||||||
|                                      `dateModified`	TEXT NOT NULL, |  | ||||||
|                                      `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                      `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                      PRIMARY KEY(`noteId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes_mig (noteId, title, isProtected, type, mime, hash, isDeleted, dateCreated, dateModified, utcDateCreated, utcDateModified) |  | ||||||
|   SELECT noteId, title, isProtected, type, mime, hash, isDeleted, REPLACE(REPLACE(dateCreated, 'T', ' '), 'Z', '+0000'), REPLACE(REPLACE(dateModified, 'T', ' '), 'Z', '+0000'), REPLACE(dateCreated, 'T', ' '), REPLACE(dateModified, 'T', ' ') FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| ALTER TABLE notes_mig RENAME TO notes; |  | ||||||
| 
 |  | ||||||
| CREATE UNIQUE INDEX `IDX_sync_entityName_entityId` ON `sync` ( |  | ||||||
|                                                               `entityName`, |  | ||||||
|                                                               `entityId` |  | ||||||
|   ); |  | ||||||
| CREATE INDEX `IDX_sync_utcSyncDate` ON `sync` ( |  | ||||||
|                                             `utcSyncDate` |  | ||||||
|   ); |  | ||||||
| CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` ( |  | ||||||
|                                                               `noteId` |  | ||||||
|   ); |  | ||||||
| CREATE INDEX `IDX_note_revisions_dateModifiedFrom` ON `note_revisions` ( |  | ||||||
|                                                                         `utcDateModifiedFrom` |  | ||||||
|   ); |  | ||||||
| CREATE INDEX `IDX_note_revisions_dateModifiedTo` ON `note_revisions` ( |  | ||||||
|                                                                       `utcDateModifiedTo` |  | ||||||
|   ); |  | ||||||
| CREATE INDEX `IDX_branches_noteId` ON `branches` ( |  | ||||||
|                                                   `noteId` |  | ||||||
|   ); |  | ||||||
| CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` ( |  | ||||||
|                                                                `noteId`, |  | ||||||
|                                                                `parentNoteId` |  | ||||||
|   ); |  | ||||||
| CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId); |  | ||||||
| CREATE INDEX IDX_attributes_name_value |  | ||||||
|   on attributes (name, value); |  | ||||||
| CREATE INDEX IDX_links_noteId_index |  | ||||||
|   on links (noteId); |  | ||||||
| CREATE INDEX IDX_links_targetNoteId_index |  | ||||||
|   on links (targetNoteId); |  | ||||||
| CREATE INDEX IDX_attributes_name_index |  | ||||||
|   on attributes (name); |  | ||||||
| CREATE INDEX IDX_attributes_noteId_index |  | ||||||
|   on attributes (noteId); |  | ||||||
| CREATE INDEX IDX_attributes_value_index |  | ||||||
|   on attributes (value); |  | ||||||
| CREATE UNIQUE INDEX `IDX_note_contents_noteId` ON `note_contents` (`noteId`); |  | ||||||
| @ -1,13 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "note_contents_mig" ( |  | ||||||
|                                                    `noteId`	TEXT NOT NULL, |  | ||||||
|                                                    `content`	TEXT NULL DEFAULT NULL, |  | ||||||
|                                                    `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                                    `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                                    PRIMARY KEY(`noteId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_contents_mig (noteId, content, hash, utcDateModified) |  | ||||||
| SELECT noteId, content, hash, utcDateModified FROM note_contents; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_contents; |  | ||||||
| ALTER TABLE note_contents_mig RENAME TO note_contents; |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| const syncTableService = require('../../src/services/entity_changes.js'); |  | ||||||
| 
 |  | ||||||
| module.exports = async () => { |  | ||||||
|     await syncTableService.fillAllSyncRows(); |  | ||||||
| }; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| DROP TABLE IF EXISTS note_fulltext; |  | ||||||
| @ -1,4 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
|     SELECT 'openTabs', '[{"notePath":"' || value || '","active": true,"tabId":"1111"}]', '2019-05-01T18:31:00.874Z', '2019-05-01T18:31:00.874Z', 0 FROM options WHERE name = 'startNotePath'; |  | ||||||
| 
 |  | ||||||
| DELETE FROM options WHERE name = 'startNotePath'; |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
|     VALUES ('hideTabRowForOneTab', 'false', '2019-05-01T18:31:00.874Z', '2019-05-01T18:31:00.874Z', 0); |  | ||||||
| @ -1,12 +0,0 @@ | |||||||
| drop table recent_notes; |  | ||||||
| 
 |  | ||||||
| create table recent_notes |  | ||||||
| ( |  | ||||||
|     noteId TEXT not null primary key, |  | ||||||
|     notePath TEXT not null, |  | ||||||
|     hash TEXT default "" not null, |  | ||||||
|     utcDateCreated TEXT not null, |  | ||||||
|     isDeleted INT |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| delete from sync where entityName = 'recent_notes'; |  | ||||||
| @ -1,10 +0,0 @@ | |||||||
| UPDATE links SET type = 'internal-link' WHERE type = 'hyper'; |  | ||||||
| UPDATE links SET type = 'image-link' WHERE type = 'image'; |  | ||||||
| UPDATE links SET type = 'relation-map-link' WHERE type = 'relation-map'; |  | ||||||
| 
 |  | ||||||
| INSERT INTO attributes (attributeId, noteId, type, name, value, position, utcDateCreated, utcDateModified, isDeleted, hash, isInheritable) |  | ||||||
| SELECT linkId, noteId, 'relation', type, targetNoteId, 0, utcDateCreated, utcDateModified, isDeleted, hash, 0 FROM links; |  | ||||||
| 
 |  | ||||||
| UPDATE sync SET entityName = 'attributes' WHERE entityName = 'links'; |  | ||||||
| 
 |  | ||||||
| DROP TABLE links; |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('sidebarMinWidth', '350', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('sidebarWidthPercent', '25', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('showSidebarInNewTab', 'true', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1,14 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('noteInfoWidget', '{"enabled":true,"expanded":true,"position":100}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('attributesWidget', '{"enabled":true,"expanded":true,"position":200}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('linkMapWidget', '{"enabled":true,"expanded":true,"position":300}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('noteRevisionsWidget', '{"enabled":true,"expanded":true,"position":400}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('whatLinksHereWidget', '{"enabled":false,"expanded":true,"position":500}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('codeNotesMimeTypes', '["text/x-csrc","text/x-c++src","text/x-csharp","text/css","text/x-go","text/x-groovy","text/x-haskell","text/html","message/http","text/x-java","application/javascript;env=frontend","application/javascript;env=backend","application/json","text/x-kotlin","text/x-markdown","text/x-perl","text/x-php","text/x-python","text/x-ruby",null,"text/x-sql","text/x-swift","text/xml","text/x-yaml"]', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 1); |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync (entityName, entityId, sourceId, utcSyncDate) |  | ||||||
| VALUES ('options' ,'codeNotesMimeTypes', 'SYNC_FILL', '2018-01-01T00:00:00.000Z'); |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('similarNotesWidget', '{"enabled":true,"expanded":true,"position":600}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1 +0,0 @@ | |||||||
| DROP TABLE event_log; |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('editedNotesWidget', '{"enabled":true,"expanded":true,"position":50}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('calendarWidget', '{"enabled":true,"expanded":true,"position":20}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('spellCheckEnabled', 'true', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| VALUES ('spellCheckLanguageCode', 'en-US', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); |  | ||||||
| @ -1,3 +0,0 @@ | |||||||
| INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced) |  | ||||||
| SELECT 'hideTabRowForOneTab', 'false', '2019-05-01T18:31:00.874Z', '2019-05-01T18:31:00.874Z', 0 |  | ||||||
| WHERE NOT EXISTS(SELECT 1 FROM options WHERE name = 'hideTabRowForOneTab'); |  | ||||||
| @ -1,22 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "mig_branches" ( |  | ||||||
|                                           `branchId`	TEXT NOT NULL, |  | ||||||
|                                           `noteId`	TEXT NOT NULL, |  | ||||||
|                                           `parentNoteId`	TEXT NOT NULL, |  | ||||||
|                                           `notePosition`	INTEGER NOT NULL, |  | ||||||
|                                           `prefix`	TEXT, |  | ||||||
|                                           `isExpanded`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|                                           `isDeleted`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|                                           `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                           utcDateCreated TEXT NOT NULL, |  | ||||||
|                                           hash TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                           PRIMARY KEY(`branchId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, utcDateModified, utcDateCreated, hash) |  | ||||||
| SELECT branchId, noteId, parentNoteId, notePosition, prefix, COALESCE(isExpanded, 0), isDeleted, utcDateModified, utcDateCreated, hash FROM branches; |  | ||||||
| 
 |  | ||||||
| DROP TABLE branches; |  | ||||||
| ALTER TABLE mig_branches RENAME TO branches; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_branches_noteId` ON `branches` (`noteId`); |  | ||||||
| CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (`noteId`,`parentNoteId`); |  | ||||||
| CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId); |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| UPDATE branches SET notePosition = notePosition * 10; |  | ||||||
| UPDATE attributes SET position = position * 10; |  | ||||||
| @ -1,36 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "note_revisions_mig" (`noteRevisionId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                                 `noteId`	TEXT NOT NULL, |  | ||||||
|                                                 `title`	TEXT, |  | ||||||
|                                                 `contentLength`	INT NOT NULL, |  | ||||||
|                                                 `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                                 `utcDateLastEdited` TEXT NOT NULL, |  | ||||||
|                                                 `utcDateCreated` TEXT NOT NULL, |  | ||||||
|                                                 `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                                 `dateLastEdited` TEXT NOT NULL, |  | ||||||
|                                                 `dateCreated` TEXT NOT NULL, |  | ||||||
|                                                 type TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                                 mime TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                                 hash TEXT DEFAULT '' NOT NULL); |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "note_revision_contents" (`noteRevisionId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                                  `content`	TEXT, |  | ||||||
|                                                  hash TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                                  `utcDateModified` TEXT NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_revision_contents (noteRevisionId, content, hash, utcDateModified) |  | ||||||
| SELECT noteRevisionId, content, hash, utcDateModifiedTo FROM note_revisions; |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_revisions_mig (noteRevisionId, noteId, title, contentLength, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated, type, mime, hash) |  | ||||||
| SELECT noteRevisionId, noteId, title, COALESCE(LENGTH(content), 0), isProtected, utcDateModifiedFrom, utcDateModifiedTo, utcDateModifiedTo, dateModifiedFrom, dateModifiedTo, type, mime, hash FROM note_revisions; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_revisions; |  | ||||||
| ALTER TABLE note_revisions_mig RENAME TO note_revisions; |  | ||||||
| 
 |  | ||||||
| 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`); |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync (entityName, entityId, sourceId, utcSyncDate) |  | ||||||
| SELECT 'note_revision_contents', entityId, sourceId, utcSyncDate FROM sync WHERE entityName = 'note_revisions'; |  | ||||||
| @ -1,31 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "notes_mig" ( |  | ||||||
|                                        `noteId`	TEXT NOT NULL, |  | ||||||
|                                        `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|                                        `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|                                        `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|                                        `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                        `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `isErased`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `dateCreated`	TEXT NOT NULL, |  | ||||||
|                                        `dateModified`	TEXT NOT NULL, |  | ||||||
|                                        `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                        `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                        PRIMARY KEY(`noteId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes_mig (noteId, title, isProtected, type, mime, hash, isDeleted, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified) |  | ||||||
| SELECT noteId, title, isProtected, type, mime, hash, isDeleted, 0, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| ALTER TABLE notes_mig RENAME TO notes; |  | ||||||
| 
 |  | ||||||
| UPDATE notes SET isErased = 1 WHERE isDeleted = 1 |  | ||||||
| AND 1=(SELECT CASE WHEN content IS NULL THEN 1 ELSE 0 END FROM note_contents WHERE note_contents.noteId = notes.noteId); |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`); |  | ||||||
| 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`); |  | ||||||
| @ -1,34 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "notes_mig" ( |  | ||||||
|                                            `noteId`	TEXT NOT NULL, |  | ||||||
|                                            `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|                                            `contentLength`	INT NOT NULL, |  | ||||||
|                                            `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                            `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|                                            `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|                                            `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                            `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                            `isErased`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                            `dateCreated`	TEXT NOT NULL, |  | ||||||
|                                            `dateModified`	TEXT NOT NULL, |  | ||||||
|                                            `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                            `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                            PRIMARY KEY(`noteId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes_mig (noteId, title, contentLength, isProtected, type, mime, hash, isDeleted, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified) |  | ||||||
| SELECT noteId, title, -1, isProtected, type, mime, hash, isDeleted, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| ALTER TABLE notes_mig RENAME TO notes; |  | ||||||
| 
 |  | ||||||
| UPDATE notes SET contentLength = COALESCE((SELECT COALESCE(LENGTH(content), 0) FROM note_contents WHERE note_contents.noteId = notes.noteId), -1); |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`); |  | ||||||
| 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`); |  | ||||||
| 
 |  | ||||||
| -- should be OK since sync protocol changes so all instances must upgrade |  | ||||||
| UPDATE attributes SET isDeleted = 1 WHERE name = 'fileSize'; |  | ||||||
| @ -1,28 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "note_revisions_mig" (`noteRevisionId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                                  `noteId`	TEXT NOT NULL, |  | ||||||
|                                                  `title`	TEXT, |  | ||||||
|                                                  `contentLength`	INT NOT NULL, |  | ||||||
|                                                  `isErased`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                                  `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                                  `utcDateLastEdited` TEXT NOT NULL, |  | ||||||
|                                                  `utcDateCreated` TEXT NOT NULL, |  | ||||||
|                                                  `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                                  `dateLastEdited` TEXT NOT NULL, |  | ||||||
|                                                  `dateCreated` TEXT NOT NULL, |  | ||||||
|                                                  type TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                                  mime TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                                  hash TEXT DEFAULT '' NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_revisions_mig (noteRevisionId, noteId, title, contentLength, isErased, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated, type, mime, hash) |  | ||||||
| SELECT noteRevisionId, noteId, title, contentLength, 0, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated, type, mime, hash FROM note_revisions; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_revisions; |  | ||||||
| ALTER TABLE note_revisions_mig RENAME TO note_revisions; |  | ||||||
| 
 |  | ||||||
| UPDATE note_revisions SET isErased = (SELECT isErased FROM notes WHERE notes.noteId = note_revisions.noteId); |  | ||||||
| 
 |  | ||||||
| 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`); |  | ||||||
| @ -1,3 +0,0 @@ | |||||||
| UPDATE attributes SET name = 'internalLink' WHERE name = 'internal-link'; |  | ||||||
| UPDATE attributes SET name = 'imageLink' WHERE name = 'image-link'; |  | ||||||
| UPDATE attributes SET name = 'relationMapLink' WHERE name = 'relation-map-link'; |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| DROP INDEX IF EXISTS IDX_attributes_name_index; |  | ||||||
| DROP INDEX IF EXISTS IDX_branches_noteId; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX IDX_source_ids_utcDateCreated |  | ||||||
|     on source_ids (utcDateCreated); |  | ||||||
| @ -1,81 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "notes_mig" ( |  | ||||||
|                                            `noteId`	TEXT NOT NULL, |  | ||||||
|                                            `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|                                            `contentLength`	INT NOT NULL, |  | ||||||
|                                            `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                            `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|                                            `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|                                            `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                            `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                            `deleteId`   TEXT DEFAULT NULL, |  | ||||||
|                                            `isErased`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                            `dateCreated`	TEXT NOT NULL, |  | ||||||
|                                            `dateModified`	TEXT NOT NULL, |  | ||||||
|                                            `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                            `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                            PRIMARY KEY(`noteId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes_mig (noteId, title, contentLength, isProtected, type, mime, hash, isDeleted, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified) |  | ||||||
| SELECT noteId, title, -1, isProtected, type, mime, hash, isDeleted, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| ALTER TABLE notes_mig RENAME TO notes; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`); |  | ||||||
| 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 "branches_mig" ( |  | ||||||
|                                           `branchId`	TEXT NOT NULL, |  | ||||||
|                                           `noteId`	TEXT NOT NULL, |  | ||||||
|                                           `parentNoteId`	TEXT NOT NULL, |  | ||||||
|                                           `notePosition`	INTEGER NOT NULL, |  | ||||||
|                                           `prefix`	TEXT, |  | ||||||
|                                           `isExpanded`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|                                           `isDeleted`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|                                           `deleteId`    TEXT DEFAULT NULL, |  | ||||||
|                                           `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                           utcDateCreated TEXT NOT NULL, |  | ||||||
|                                           hash TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                           PRIMARY KEY(`branchId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO branches_mig (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, utcDateModified, utcDateCreated, hash) |  | ||||||
|     SELECT branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, utcDateModified, utcDateCreated, hash FROM branches; |  | ||||||
| 
 |  | ||||||
| DROP TABLE branches; |  | ||||||
| ALTER TABLE branches_mig RENAME TO branches; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (`noteId`,`parentNoteId`); |  | ||||||
| CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId); |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "attributes_mig" |  | ||||||
| ( |  | ||||||
|     attributeId      TEXT not null primary key, |  | ||||||
|     noteId       TEXT not null, |  | ||||||
|     type         TEXT not null, |  | ||||||
|     name         TEXT not null, |  | ||||||
|     value        TEXT default '' not null, |  | ||||||
|     position     INT  default 0 not null, |  | ||||||
|     utcDateCreated  TEXT not null, |  | ||||||
|     utcDateModified TEXT not null, |  | ||||||
|     isDeleted    INT  not null, |  | ||||||
|     `deleteId`    TEXT DEFAULT NULL, |  | ||||||
|     hash         TEXT default "" not null, |  | ||||||
|     isInheritable int DEFAULT 0 NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO attributes_mig (attributeId, noteId, type, name, value, position, utcDateCreated, utcDateModified, isDeleted, hash, isInheritable) |  | ||||||
| SELECT attributeId, noteId, type, name, value, position, utcDateCreated, utcDateModified, isDeleted, hash, isInheritable FROM attributes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE attributes; |  | ||||||
| ALTER TABLE attributes_mig RENAME TO attributes; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX IDX_attributes_name_value |  | ||||||
|     on attributes (name, value); |  | ||||||
| CREATE INDEX IDX_attributes_noteId_index |  | ||||||
|     on attributes (noteId); |  | ||||||
| CREATE INDEX IDX_attributes_value_index |  | ||||||
|     on attributes (value); |  | ||||||
| @ -1 +0,0 @@ | |||||||
| UPDATE notes SET contentLength = COALESCE((SELECT COALESCE(LENGTH(content), 0) FROM note_contents WHERE note_contents.noteId = notes.noteId), -1); |  | ||||||
| @ -1,22 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "sync_mig" ( |  | ||||||
|                                           `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |  | ||||||
|                                           `entityName`	TEXT NOT NULL, |  | ||||||
|                                           `entityId`	TEXT NOT NULL, |  | ||||||
|                                           `sourceId` TEXT NOT NULL, |  | ||||||
|                                           `isSynced` INTEGER default 0 not null, |  | ||||||
|                                           `utcSyncDate`	TEXT NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO sync_mig (id, entityName, entityId, sourceId, isSynced, utcSyncDate) |  | ||||||
| SELECT id, entityName, entityId, sourceId, 1, utcSyncDate FROM sync; |  | ||||||
| 
 |  | ||||||
| DROP TABLE sync; |  | ||||||
| 
 |  | ||||||
| ALTER TABLE sync_mig RENAME TO sync; |  | ||||||
| 
 |  | ||||||
| CREATE UNIQUE INDEX `IDX_sync_entityName_entityId` ON `sync` ( |  | ||||||
|                                                               `entityName`, |  | ||||||
|                                                               `entityId` |  | ||||||
|     ); |  | ||||||
| CREATE INDEX `IDX_sync_utcSyncDate` ON `sync` ( |  | ||||||
|                                                `utcSyncDate` |  | ||||||
|     ); |  | ||||||
| @ -1,4 +0,0 @@ | |||||||
| UPDATE sync SET isSynced = 1 WHERE entityName != 'options' OR ( |  | ||||||
|         entityName = 'options' |  | ||||||
|         AND 1 = (SELECT isSynced FROM options WHERE name = sync.entityId) |  | ||||||
|     ) |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| UPDATE attributes SET type = 'label', name = 'label:' || name WHERE type = 'label-definition'; |  | ||||||
| UPDATE attributes SET type = 'label', name = 'relation:' || name WHERE type = 'relation-definition'; |  | ||||||
| @ -1,79 +0,0 @@ | |||||||
| const sql = require('../../src/services/sql'); |  | ||||||
| 
 |  | ||||||
| module.exports = () => { |  | ||||||
|     for (const attr of sql.getRows("SELECT * FROM attributes WHERE name LIKE 'label:%'")) { |  | ||||||
|         let obj; |  | ||||||
| 
 |  | ||||||
|         try { |  | ||||||
|             obj = JSON.parse(attr.value); |  | ||||||
|         } |  | ||||||
|         catch (e) { |  | ||||||
|             console.log(`Parsing attribute definition "${attr.value}" of ${attr.attributeId} failed with error "${e.message}", setting to default value.`); |  | ||||||
| 
 |  | ||||||
|             sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?', |  | ||||||
|                 ["multi,text", attr.attributeId]); |  | ||||||
| 
 |  | ||||||
|             continue; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const tokens = []; |  | ||||||
| 
 |  | ||||||
|         if (obj.isPromoted) { |  | ||||||
|             tokens.push('promoted'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (obj.multiplicityType === 'singlevalue') { |  | ||||||
|             tokens.push('single'); |  | ||||||
|         } else if (obj.multiplicityType === 'multivalue') { |  | ||||||
|             tokens.push('multi'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (obj.labelType) { |  | ||||||
|             tokens.push(obj.labelType); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (obj.numberPrecision) { |  | ||||||
|             tokens.push('precision='+obj.numberPrecision); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const newValue = tokens.join(','); |  | ||||||
| 
 |  | ||||||
|         sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?', [newValue, attr.attributeId]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     for (const attr of sql.getRows("SELECT * FROM attributes WHERE name LIKE 'relation:%'")) { |  | ||||||
|         let obj; |  | ||||||
| 
 |  | ||||||
|         try { |  | ||||||
|             obj = JSON.parse(attr.value); |  | ||||||
|         } |  | ||||||
|         catch (e) { |  | ||||||
|             console.log(`Parsing attribute definition "${attr.value}" of ${attr.attributeId} failed with error "${e.message}", setting to default value.`); |  | ||||||
| 
 |  | ||||||
|             sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?', |  | ||||||
|                 ["multi", attr.attributeId]); |  | ||||||
| 
 |  | ||||||
|             continue; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const tokens = []; |  | ||||||
| 
 |  | ||||||
|         if (obj.isPromoted) { |  | ||||||
|             tokens.push('promoted'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (obj.multiplicityType === 'singlevalue') { |  | ||||||
|             tokens.push('single'); |  | ||||||
|         } else if (obj.multiplicityType === 'multivalue') { |  | ||||||
|             tokens.push('multi'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (obj.inverseRelation) { |  | ||||||
|             tokens.push('inverse=' + obj.inverseRelation); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         const newValue = tokens.join(','); |  | ||||||
| 
 |  | ||||||
|         sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?', [newValue, attr.attributeId]); |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| DROP TABLE source_ids; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| ALTER TABLE sync RENAME TO entity_changes; |  | ||||||
| @ -1,22 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "mig_entity_changes" ( |  | ||||||
|                                                 `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |  | ||||||
|                                                 `entityName`	TEXT NOT NULL, |  | ||||||
|                                                 `entityId`	TEXT NOT NULL, |  | ||||||
|                                                 `sourceId` TEXT NOT NULL, |  | ||||||
|                                                 `isSynced` INTEGER default 0 not null, |  | ||||||
|                                                 `utcChangedDate`	TEXT NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_entity_changes (id, entityName, entityId, sourceId, isSynced, utcChangedDate) |  | ||||||
|     SELECT id, entityName, entityId, sourceId, isSynced, utcSyncDate FROM entity_changes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE entity_changes; |  | ||||||
| 
 |  | ||||||
| ALTER TABLE mig_entity_changes RENAME TO entity_changes; |  | ||||||
| 
 |  | ||||||
| CREATE UNIQUE INDEX `IDX_entityChanges_entityName_entityId` ON "entity_changes" ( |  | ||||||
|                                                                                  `entityName`, |  | ||||||
|                                                                                  `entityId` |  | ||||||
|     ); |  | ||||||
| CREATE INDEX `IDX_entityChanges_utcChangedDate` ON "entity_changes" ( |  | ||||||
|                                                                   `utcChangedDate` |  | ||||||
|     ); |  | ||||||
| @ -1,55 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "notes_mig" ( |  | ||||||
|                                        `noteId`	TEXT NOT NULL, |  | ||||||
|                                        `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|                                        `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|                                        `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|                                        `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                        `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `deleteId`   TEXT DEFAULT NULL, |  | ||||||
|                                        `isErased`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `dateCreated`	TEXT NOT NULL, |  | ||||||
|                                        `dateModified`	TEXT NOT NULL, |  | ||||||
|                                        `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                        `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                        PRIMARY KEY(`noteId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO notes_mig (noteId, title, isProtected, type, mime, hash, isDeleted, deleteId, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified) |  | ||||||
|     SELECT noteId, title, isProtected, type, mime, hash, isDeleted, deleteId, isErased, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| ALTER TABLE notes_mig RENAME TO notes; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`); |  | ||||||
| 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_revisions_mig" (`noteRevisionId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                              `noteId`	TEXT NOT NULL, |  | ||||||
|                                              `title`	TEXT, |  | ||||||
|                                              `isErased`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                              `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                              `utcDateLastEdited` TEXT NOT NULL, |  | ||||||
|                                              `utcDateCreated` TEXT NOT NULL, |  | ||||||
|                                              `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                              `dateLastEdited` TEXT NOT NULL, |  | ||||||
|                                              `dateCreated` TEXT NOT NULL, |  | ||||||
|                                              type TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                              mime TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                              hash TEXT DEFAULT '' NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_revisions_mig (noteRevisionId, noteId, title, isErased, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated, type, mime, hash) |  | ||||||
| SELECT noteRevisionId, noteId, title, isErased, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated, type, mime, hash FROM note_revisions; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_revisions; |  | ||||||
| ALTER TABLE note_revisions_mig RENAME TO note_revisions; |  | ||||||
| 
 |  | ||||||
| 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`); |  | ||||||
| @ -1,20 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "note_contents_mig" ( |  | ||||||
|                                                `noteId`	TEXT NOT NULL, |  | ||||||
|                                                `content`	TEXT NULL DEFAULT NULL, |  | ||||||
|                                                `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|                                                `dateModified` TEXT NOT NULL, |  | ||||||
|                                                `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                                PRIMARY KEY(`noteId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO note_contents_mig (noteId, content, hash, dateModified, utcDateModified) |  | ||||||
|     SELECT noteId, |  | ||||||
|            content, |  | ||||||
|            hash, |  | ||||||
|            COALESCE((SELECT dateModified FROM notes WHERE noteId = note_contents.noteId), utcDateModified), |  | ||||||
|            utcDateModified |  | ||||||
|     FROM note_contents; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_contents; |  | ||||||
| 
 |  | ||||||
| ALTER TABLE note_contents_mig RENAME TO note_contents; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| DELETE FROM options WHERE name = 'keyboardShortcutsActivateParentNote'; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| UPDATE attributes SET name = 'archived' WHERE name = 'hideInAutocomplete'; |  | ||||||
| @ -1,20 +0,0 @@ | |||||||
| const repository = require('../../src/services/repository'); |  | ||||||
| 
 |  | ||||||
| module.exports = () => { |  | ||||||
|     for (const note of repository.getEntities("SELECT * FROM notes WHERE type = 'text' AND isProtected = 0")) { |  | ||||||
|         try { |  | ||||||
|             let origContent = note.getContent(); |  | ||||||
| 
 |  | ||||||
|             const newContent = origContent |  | ||||||
|                 .replace(/<h1/ig, "<h2") |  | ||||||
|                 .replace(/<\/h1/ig, "</h2"); |  | ||||||
| 
 |  | ||||||
|             if (newContent !== origContent) { |  | ||||||
|                 note.setContent(newContent); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         catch (e) { |  | ||||||
|             console.log(`Changing note content for note ${note.noteId} failed with: ${e.message} ${e.stack}`); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| @ -1,14 +0,0 @@ | |||||||
| const repository = require('../../src/services/repository'); |  | ||||||
| const sql = require('../../src/services/sql'); |  | ||||||
| 
 |  | ||||||
| module.exports = () => { |  | ||||||
|     for (const note of repository.getEntities("SELECT * FROM notes")) { |  | ||||||
|         let position = 0; |  | ||||||
| 
 |  | ||||||
|         for (const branch of note.getChildBranches()) { |  | ||||||
|             sql.execute(`UPDATE branches SET notePosition = ? WHERE branchId = ?`, [position, branch.branchId]); |  | ||||||
| 
 |  | ||||||
|             position += 10; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| @ -1,15 +0,0 @@ | |||||||
| DELETE FROM options WHERE name IN ( |  | ||||||
|     'noteInfoWidget', |  | ||||||
|     'attributesWidget', |  | ||||||
|     'linkMapWidget', |  | ||||||
|     'noteRevisionsWidget', |  | ||||||
|     'whatLinksHereWidget', |  | ||||||
|     'codeNotesMimeTypes', |  | ||||||
|     'similarNotesWidget', |  | ||||||
|     'editedNotesWidget', |  | ||||||
|     'calendarWidget', |  | ||||||
|     'sidebarMinWidth', |  | ||||||
|     'sidebarWidthPercent', |  | ||||||
|     'showSidebarInNewTab', |  | ||||||
|     'hoistedNoteId' |  | ||||||
| ); |  | ||||||
| @ -1,69 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "mig_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); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_entity_changes (id, entityName, entityId, hash, sourceId, isSynced, utcDateChanged, isErased) |  | ||||||
| SELECT id, entityName, entityId, '', sourceId, isSynced, utcChangedDate, 0 FROM entity_changes; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET isErased = COALESCE((SELECT isErased FROM notes WHERE noteId = entityId), 0) WHERE entityName = 'notes'; |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM notes WHERE noteId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'notes'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET isErased = COALESCE((SELECT isErased FROM notes WHERE noteId = entityId), 0) WHERE entityName = 'note_contents'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET isErased = COALESCE(( |  | ||||||
|     SELECT isErased |  | ||||||
|     FROM attributes |  | ||||||
|          JOIN notes USING(noteId) |  | ||||||
|     WHERE attributeId = entityId |  | ||||||
| ), 0) WHERE entityName = 'attributes'; |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM attributes WHERE attributeId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'attributes'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET isErased = COALESCE(( |  | ||||||
|     SELECT isErased |  | ||||||
|     FROM branches |  | ||||||
|     JOIN notes USING(noteId) |  | ||||||
|     WHERE branchId = entityId |  | ||||||
| ), 0) WHERE entityName = 'branches'; |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM branches WHERE branchId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'branches'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET isErased = COALESCE(( |  | ||||||
|     SELECT isErased |  | ||||||
|     FROM note_revisions |  | ||||||
|     WHERE noteRevisionId = entityId |  | ||||||
| ), 0) WHERE entityName = 'note_revisions'; |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM note_revisions WHERE noteRevisionId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'note_revisions'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateCreated FROM api_tokens WHERE apiTokenId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'api_tokens'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM note_contents WHERE noteId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'note_contents'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM note_revision_contents WHERE noteRevisionId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'note_revision_contents'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM options WHERE name = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'options'; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateCreated FROM recent_notes WHERE noteId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'options'; |  | ||||||
| 
 |  | ||||||
| DROP TABLE entity_changes; |  | ||||||
| ALTER TABLE mig_entity_changes RENAME TO entity_changes; |  | ||||||
| 
 |  | ||||||
| CREATE UNIQUE INDEX `IDX_entityChanges_entityName_entityId` ON "entity_changes" ( |  | ||||||
|                                                                                  `entityName`, |  | ||||||
|                                                                                  `entityId` |  | ||||||
|     ); |  | ||||||
| 
 |  | ||||||
| DELETE FROM attributes WHERE noteId IN (SELECT noteId FROM notes WHERE isErased = 1); |  | ||||||
| DELETE FROM branches WHERE noteId IN (SELECT noteId FROM notes WHERE isErased = 1); |  | ||||||
| DELETE FROM note_contents WHERE noteId IN (SELECT noteId FROM notes WHERE isErased = 1); |  | ||||||
| DELETE FROM note_revision_contents WHERE noteRevisionId IN ( |  | ||||||
|     SELECT noteRevisionId FROM note_revisions WHERE isErased = 1 |  | ||||||
| ); |  | ||||||
| DELETE FROM note_revisions WHERE isErased = 1; |  | ||||||
| DELETE FROM notes WHERE isErased = 1; |  | ||||||
| 
 |  | ||||||
| UPDATE entity_changes SET isErased = COALESCE((SELECT isErased FROM entity_changes AS sub WHERE sub.entityId = entity_changes.entityId AND sub.entityName = 'note_revisions'), 0) WHERE entityName = 'note_revision_contents'; |  | ||||||
| @ -1,198 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "mig_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 |  | ||||||
|                                                 ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_entity_changes (id, entityName, entityId, hash, sourceId, isSynced, isErased, utcDateChanged) |  | ||||||
|     SELECT id, entityName, entityId, '', sourceId, isSynced, isErased, utcDateChanged FROM entity_changes; |  | ||||||
| 
 |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM api_tokens WHERE apiTokenId = entityId), '') WHERE entityName = 'api_tokens'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM attributes WHERE attributeId = entityId), '') WHERE entityName = 'attributes'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM branches WHERE branchId = entityId), '') WHERE entityName = 'branches'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM notes WHERE noteId = entityId), '') WHERE entityName = 'notes'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM note_contents WHERE noteId = entityId), '') WHERE entityName = 'note_contents'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM note_revisions WHERE noteRevisionId = entityId), '') WHERE entityName = 'note_revisions'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM note_revision_contents WHERE noteRevisionId = entityId), '') WHERE entityName = 'note_revision_contents'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM options WHERE name = entityId), '') WHERE entityName = 'options'; |  | ||||||
| UPDATE mig_entity_changes SET hash = COALESCE((SELECT hash FROM recent_notes WHERE noteId = entityId), '') WHERE entityName = 'recent_notes'; |  | ||||||
| 
 |  | ||||||
| DROP TABLE entity_changes; |  | ||||||
| ALTER TABLE mig_entity_changes RENAME TO entity_changes; |  | ||||||
| 
 |  | ||||||
| CREATE UNIQUE INDEX `IDX_entityChanges_entityName_entityId` ON "entity_changes" ( |  | ||||||
|                                                                                  `entityName`, |  | ||||||
|                                                                                  `entityId` |  | ||||||
|     ); |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "mig_api_tokens" |  | ||||||
| ( |  | ||||||
|     apiTokenId TEXT PRIMARY KEY NOT NULL, |  | ||||||
|     token TEXT NOT NULL, |  | ||||||
|     utcDateCreated TEXT NOT NULL, |  | ||||||
|     isDeleted INT NOT NULL DEFAULT 0); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_api_tokens (apiTokenId, token, utcDateCreated, isDeleted) |  | ||||||
| SELECT apiTokenId, token, utcDateCreated, isDeleted FROM api_tokens; |  | ||||||
| 
 |  | ||||||
| DROP TABLE api_tokens; |  | ||||||
| ALTER TABLE mig_api_tokens RENAME TO api_tokens; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "mig_attributes" |  | ||||||
| ( |  | ||||||
|     attributeId      TEXT not null primary key, |  | ||||||
|     noteId       TEXT not null, |  | ||||||
|     type         TEXT not null, |  | ||||||
|     name         TEXT not null, |  | ||||||
|     value        TEXT default '' not null, |  | ||||||
|     position     INT  default 0 not null, |  | ||||||
|     utcDateCreated  TEXT not null, |  | ||||||
|     utcDateModified TEXT not null, |  | ||||||
|     isDeleted    INT  not null, |  | ||||||
|     `deleteId`    TEXT DEFAULT NULL, |  | ||||||
|     isInheritable int DEFAULT 0 NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_attributes (attributeId, noteId, type, name, value, position, utcDateCreated, utcDateModified, isDeleted, deleteId, isInheritable) |  | ||||||
| SELECT attributeId, noteId, type, name, value, position, utcDateCreated, utcDateModified, isDeleted, deleteId, isInheritable FROM attributes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE attributes; |  | ||||||
| ALTER TABLE mig_attributes RENAME TO attributes; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX IDX_attributes_name_value |  | ||||||
|     on attributes (name, value); |  | ||||||
| CREATE INDEX IDX_attributes_noteId_index |  | ||||||
|     on attributes (noteId); |  | ||||||
| CREATE INDEX IDX_attributes_value_index |  | ||||||
|     on attributes (value); |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "mig_branches" ( |  | ||||||
|                                           `branchId`	TEXT NOT NULL, |  | ||||||
|                                           `noteId`	TEXT NOT NULL, |  | ||||||
|                                           `parentNoteId`	TEXT NOT NULL, |  | ||||||
|                                           `notePosition`	INTEGER NOT NULL, |  | ||||||
|                                           `prefix`	TEXT, |  | ||||||
|                                           `isExpanded`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|                                           `isDeleted`	INTEGER NOT NULL DEFAULT 0, |  | ||||||
|                                           `deleteId`    TEXT DEFAULT NULL, |  | ||||||
|                                           `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                           utcDateCreated TEXT NOT NULL, |  | ||||||
|                                           PRIMARY KEY(`branchId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, deleteId, utcDateModified, utcDateCreated) |  | ||||||
| SELECT branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, deleteId, utcDateModified, utcDateCreated FROM branches; |  | ||||||
| 
 |  | ||||||
| DROP TABLE branches; |  | ||||||
| ALTER TABLE mig_branches RENAME TO branches; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (`noteId`,`parentNoteId`); |  | ||||||
| CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId); |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "mig_notes" ( |  | ||||||
|                                        `noteId`	TEXT NOT NULL, |  | ||||||
|                                        `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|                                        `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|                                        `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|                                        `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                        `deleteId`   TEXT DEFAULT NULL, |  | ||||||
|                                        `dateCreated`	TEXT NOT NULL, |  | ||||||
|                                        `dateModified`	TEXT NOT NULL, |  | ||||||
|                                        `utcDateCreated`	TEXT NOT NULL, |  | ||||||
|                                        `utcDateModified`	TEXT NOT NULL, |  | ||||||
|                                        PRIMARY KEY(`noteId`)); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_notes (noteId, title, isProtected, type, mime, isDeleted, deleteId, dateCreated, dateModified, utcDateCreated, utcDateModified) |  | ||||||
| SELECT noteId, title, isProtected, type, mime, isDeleted, deleteId, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE notes; |  | ||||||
| ALTER TABLE mig_notes RENAME TO notes; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`); |  | ||||||
| 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 "mig_note_contents" ( |  | ||||||
|                                                `noteId`	TEXT NOT NULL, |  | ||||||
|                                                `content`	TEXT NULL DEFAULT NULL, |  | ||||||
|                                                `dateModified` TEXT NOT NULL, |  | ||||||
|                                                `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                                PRIMARY KEY(`noteId`) |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_note_contents (noteId, content, dateModified, utcDateModified) |  | ||||||
| SELECT noteId, content, dateModified, utcDateModified FROM note_contents; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_contents; |  | ||||||
| ALTER TABLE mig_note_contents RENAME TO note_contents; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "mig_note_revisions" (`noteRevisionId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                              `noteId`	TEXT NOT NULL, |  | ||||||
|                                              type TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                              mime TEXT DEFAULT '' NOT NULL, |  | ||||||
|                                              `title`	TEXT, |  | ||||||
|                                              `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|                                              `utcDateLastEdited` TEXT NOT NULL, |  | ||||||
|                                              `utcDateCreated` TEXT NOT NULL, |  | ||||||
|                                              `utcDateModified` TEXT NOT NULL, |  | ||||||
|                                              `dateLastEdited` TEXT NOT NULL, |  | ||||||
|                                              `dateCreated` TEXT NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_note_revisions (noteRevisionId, noteId, type, mime, title, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated) |  | ||||||
| SELECT noteRevisionId, noteId, type, mime, title, isProtected, utcDateLastEdited, utcDateCreated, utcDateModified, dateLastEdited, dateCreated FROM note_revisions; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_revisions; |  | ||||||
| ALTER TABLE mig_note_revisions RENAME TO note_revisions; |  | ||||||
| 
 |  | ||||||
| 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 "mig_note_revision_contents" (`noteRevisionId`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|                                                      `content`	TEXT, |  | ||||||
|                                                      `utcDateModified` TEXT NOT NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_note_revision_contents (noteRevisionId, content, utcDateModified) |  | ||||||
| SELECT noteRevisionId, content, utcDateModified FROM note_revision_contents; |  | ||||||
| 
 |  | ||||||
| DROP TABLE note_revision_contents; |  | ||||||
| ALTER TABLE mig_note_revision_contents RENAME TO note_revision_contents; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "mig_options" |  | ||||||
| ( |  | ||||||
|     name TEXT not null PRIMARY KEY, |  | ||||||
|     value TEXT, |  | ||||||
|     isSynced INTEGER default 0 not null, |  | ||||||
|     utcDateCreated TEXT not null, |  | ||||||
|     utcDateModified TEXT NOT NULL |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_options (name, value, isSynced, utcDateCreated, utcDateModified) |  | ||||||
| SELECT name, value, isSynced, utcDateCreated, utcDateModified FROM options; |  | ||||||
| 
 |  | ||||||
| DROP TABLE options; |  | ||||||
| ALTER TABLE mig_options RENAME TO options; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE mig_recent_notes |  | ||||||
| ( |  | ||||||
|     noteId TEXT not null primary key, |  | ||||||
|     notePath TEXT not null, |  | ||||||
|     utcDateCreated TEXT not null, |  | ||||||
|     isDeleted INT NOT NULL DEFAULT 0 |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_recent_notes (noteId, notePath, utcDateCreated, isDeleted) |  | ||||||
| SELECT noteId, notePath, utcDateCreated, isDeleted FROM recent_notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE recent_notes; |  | ||||||
| ALTER TABLE mig_recent_notes RENAME TO recent_notes; |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| UPDATE options SET name = 'eraseEntitiesAfterTimeInSeconds' WHERE name = 'eraseNotesAfterTimeInSeconds'; |  | ||||||
| UPDATE entity_changes SET entityId = 'eraseEntitiesAfterTimeInSeconds' WHERE entityName = 'options' AND entityId = 'eraseNotesAfterTimeInSeconds'; |  | ||||||
| @ -1,25 +0,0 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "mig_attributes" |  | ||||||
| ( |  | ||||||
|     attributeId      TEXT not null primary key, |  | ||||||
|     noteId       TEXT not null, |  | ||||||
|     type         TEXT not null, |  | ||||||
|     name         TEXT not null, |  | ||||||
|     value        TEXT default '' not null, |  | ||||||
|     position     INT  default 0 not null, |  | ||||||
|     utcDateModified TEXT not null, |  | ||||||
|     isDeleted    INT  not null, |  | ||||||
|     `deleteId`    TEXT DEFAULT NULL, |  | ||||||
|     isInheritable int DEFAULT 0 NULL); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_attributes (attributeId, noteId, type, name, value, position, utcDateModified, isDeleted, deleteId, isInheritable) |  | ||||||
| SELECT attributeId, noteId, type, name, value, position, utcDateModified, isDeleted, deleteId, isInheritable FROM attributes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE attributes; |  | ||||||
| ALTER TABLE mig_attributes RENAME TO attributes; |  | ||||||
| 
 |  | ||||||
| CREATE INDEX IDX_attributes_name_value |  | ||||||
|     on attributes (name, value); |  | ||||||
| CREATE INDEX IDX_attributes_noteId_index |  | ||||||
|     on attributes (noteId); |  | ||||||
| CREATE INDEX IDX_attributes_value_index |  | ||||||
|     on attributes (value); |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| DELETE FROM options WHERE name = 'keyboardShortcutsCreateNoteIntoInbox'; -- in case there is already one which shouldn't (except for in-dev documents) |  | ||||||
| UPDATE options SET name = 'keyboardShortcutsCreateNoteIntoInbox' WHERE name = 'keyboardShortcutsCreateNoteIntoDayNote'; |  | ||||||
| 
 |  | ||||||
| DELETE FROM options WHERE name = 'keyboardShortcutsShowAttributes'; |  | ||||||
| DELETE FROM entity_changes WHERE entityName = 'options' AND entityId = 'keyboardShortcutsShowAttributes'; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| DROP INDEX IDX_notes_isDeleted; |  | ||||||
| @ -1 +0,0 @@ | |||||||
| VACUUM |  | ||||||
| @ -1,2 +0,0 @@ | |||||||
| UPDATE options SET name = 'keyboardShortcutsQuickSearch' WHERE name = 'keyboardShortcutsSearchNotes'; |  | ||||||
| UPDATE entity_changes SET entityId = 'keyboardShortcutsQuickSearch' WHERE entityId = 'keyboardShortcutsSearchNotes' AND entityName = 'options'; |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| UPDATE entity_changes SET isSynced = COALESCE(( |  | ||||||
|     SELECT options.isSynced |  | ||||||
|     FROM options |  | ||||||
|     WHERE options.name = entity_changes.entityId |  | ||||||
| ), 0) WHERE entityName = 'options'; |  | ||||||
| @ -1,14 +0,0 @@ | |||||||
| DELETE FROM entity_changes WHERE entityName = 'recent_notes'; |  | ||||||
| 
 |  | ||||||
| CREATE TABLE IF NOT EXISTS "mig_recent_notes" |  | ||||||
| ( |  | ||||||
|     noteId TEXT not null primary key, |  | ||||||
|     notePath TEXT not null, |  | ||||||
|     utcDateCreated TEXT not null |  | ||||||
| ); |  | ||||||
| 
 |  | ||||||
| INSERT INTO mig_recent_notes (noteId, notePath, utcDateCreated) |  | ||||||
|     SELECT noteId, notePath, utcDateCreated FROM recent_notes; |  | ||||||
| 
 |  | ||||||
| DROP TABLE recent_notes; |  | ||||||
| ALTER TABLE mig_recent_notes RENAME TO recent_notes; |  | ||||||
| @ -1,25 +0,0 @@ | |||||||
| const repository = require('../../src/services/repository'); |  | ||||||
| 
 |  | ||||||
| module.exports = () => { |  | ||||||
|     for (const note of repository.getEntities("SELECT * FROM notes WHERE type = 'search' AND isProtected = 0 AND isDeleted = 0")) { |  | ||||||
|         try { |  | ||||||
|             let origContent = note.getJsonContent(); |  | ||||||
| 
 |  | ||||||
|             if (!origContent) { |  | ||||||
|                 continue; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             note.addLabel('searchString', origContent.searchString); |  | ||||||
| 
 |  | ||||||
|             note.setContent(''); |  | ||||||
| 
 |  | ||||||
|             note.mime = 'text/plain'; |  | ||||||
|             note.save(); |  | ||||||
| 
 |  | ||||||
|             console.log(`Migrated search note ${note.noteId}`); |  | ||||||
|         } |  | ||||||
|         catch (e) { |  | ||||||
|             console.log(`Changing note content for note ${note.noteId} failed with: ${e.message} ${e.stack}`); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam