OJD Commit: Fix node id reset
[eidogo-ojd.git] / php / ojd_structure.sql
bloba23077cc7c29850b2cd493c127cbd301c5eddc5e
1 # The main variations tree lives in table tree_node, referencing the current
2 # version of the nodes in tree_node_archive. Each node has a set of SGF nodes
3 # (sgf_node), set of attributed comments (node_comment), editorial comment
4 # and possibly other metadata later.
7 DROP TABLE sgf_node;
8 DROP TABLE tree_node;
9 DROP TABLE tree_node_archive;
12 CREATE TABLE tree_node_archive (
13         id INT AUTO_INCREMENT PRIMARY KEY,
15         # Non-authoritative commentary (e.g. short description of upcoming variations)
16         editorial TEXT
17 ) ENGINE=InnoDB;
19 CREATE TABLE tree_node (
20         id INT AUTO_INCREMENT PRIMARY KEY,
21         parent INT DEFAULT NULL,
22         FOREIGN KEY (parent) REFERENCES tree_node (id) ON DELETE CASCADE,
24         version INT NOT NULL,
25         FOREIGN KEY (version) REFERENCES tree_node_archive (id)
26 ) ENGINE=InnoDB;
29 # Board-related SGF node
30 # This should be used only for trivial SGF nodes; any metadata should be
31 # stored in proper table columns.
32 CREATE TABLE sgf_node (
33         id INT AUTO_INCREMENT PRIMARY KEY,
35         tnode INT NOT NULL,
36         FOREIGN KEY (tnode) REFERENCES tree_node_archive (id) ON DELETE CASCADE,
38         code VARCHAR(2),
39         value VARCHAR(8)
40 ) ENGINE=InnoDB;
43 INSERT INTO tree_node_archive SET editorial="The Road Begins Here";
44 INSERT INTO tree_node SET version=1;