trilium/db/migrations/0125__create_note_content_table.sql

36 lines
1.2 KiB
MySQL
Raw Normal View History

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,
2019-02-07 04:29:23 +08:00
`hash` TEXT DEFAULT "" NOT NULL,
2019-02-15 07:15:09 +08:00
`dateCreated` TEXT NOT NULL,
`dateModified` TEXT NOT NULL,
PRIMARY KEY(`noteContentId`)
);
CREATE UNIQUE INDEX `IDX_note_contents_noteId` ON `note_contents` (`noteId`);
2019-02-16 04:10:00 +08:00
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;