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

35 lines
964 B
MySQL
Raw Normal View History

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