DROP TABLE IF EXISTS notes;
DROP TABLE IF EXISTS note_relationships;
DROP TABLE IF EXISTS pages;
DROP TABLE IF EXISTS page_relationships;
DROP TABLE IF EXISTS favorites;

CREATE TABLE notes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    uuid TEXT NOT NULL UNIQUE,
    notetype TEXT,
)

CREATE TABLE pages (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    slug text NOT NULL UNIQUE,
    note_id INTEGER,
    FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE NO ACTION ON UPDATE NO ACTION
)

CREATE TABLE note_relationships (
    note_id INTEGER NOT NULL,
    parent_id INTEGER NOT NULL,
    position INTEGER NOT NULL,
    nature TEXT NOT NULL,
    FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY (parent_id) REFERENCES notes (id) ON DELETE NO ACTION ON UPDATE NO ACTION
);

CREATE TABLE page_relationships (
    note_id INTEGER NOT NULL,
	page_id INTEGER NOT NULL,
	FOREIGN KEY (note_id) references notes (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
	FOREIGN KEY (page_id) references pages (id) ON DELETE NO ACTION ON UPDATE NO ACTION
);

	
