notesmachine/server/nm-store/src/sql/initialize_database.sql

34 lines
909 B
MySQL
Raw Normal View History

DROP TABLE IF EXISTS notes;
DROP TABLE IF EXISTS note_relationships;
DROP INDEX IF EXISTS note_ids;
DROP TABLE IF EXISTS favorites;
CREATE TABLE notes (
2020-11-03 02:32:01 +00:00
id TEXT NOT NULL PRIMARY KEY,
content TEXT NOT NULL,
kind TEXT NOT NULL,
creation_date DATETIME NOT NULL,
updated_date DATETIME NOT NULL,
lastview_date DATETIME NOT NULL,
deleted_date DATETIME NULL
);
CREATE INDEX note_ids ON notes (id);
CREATE TABLE favorites (
2020-11-03 02:32:01 +00:00
id TEXT NOT NULL,
location INTEGER NOT NULL,
FOREIGN KEY (id) REFERENCES notes (id) ON DELETE CASCADE
);
CREATE TABLE note_relationships (
note_id TEXT NOT NULL,
2020-11-03 02:32:01 +00:00
parent_id TEXT NOT NULL,
location INTEGER NOT NULL,
kind TEXT NOT NULL,
-- If either note disappears, we want all the edges to disappear as well.
FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE CASCADE,
FOREIGN KEY (parent_id) REFERENCES notes (id) ON DELETE CASCADE
);