DROP TABLE IF EXISTS Pages;
DROP TABLE IF EXISTS Folders;

-- CREATE TABLES

CREATE TABLE Folders (
    folderId INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    folderName VARCHAR(50) NOT NULL,
    folderParent INT UNSIGNED,

    CONSTRAINT sf_folderParent_folderId FOREIGN KEY (folderParent) REFERENCES Folders(folderId) ON DELETE CASCADE
);

CREATE TABLE Pages (
    pageId INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    pageTitle VARCHAR(50) NOT NULL,
    pageFolder INT UNSIGNED,
    pageContent TEXT,

    CONSTRAINT fk_pages_folder FOREIGN KEY (pageFolder) REFERENCES Folders(folderId) ON DELETE CASCADE
);

-- Populate Tables


INSERT INTO Folders (folderId, folderName, folderParent) VALUES
(1, "animaux", NULL),
(2, "mamifère", 1),
(3, "plantes", NULL);

INSERT INTO Pages (pageTitle, pageFolder, pageContent) VALUES
('Vache', 2, 'La vache est un mamifères'),
('Pin des Landes', NULL,  'Le pin des landes est un pin que lon retrouve dans les landes'),
('Le lézard', 1, 'Le lézard est un reptile à sang froid');