OJD db: tree_node_archive.tree_pos references back tree_node.id
[eidogo-ojd.git] / php / ojd_structure.sql
blobddde59165abab653a0a8c1766ac3749a90414f83
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,
14         tree_pos INT NOT NULL,
15         FOREIGN KEY (tree_pos) REFERENCES tree_node (id),
17         # Also IPv6 addresses and other junk!
18         author VARCHAR(128)
19 ) ENGINE=InnoDB;
21 CREATE TABLE tree_node (
22         id INT AUTO_INCREMENT PRIMARY KEY,
23         parent INT DEFAULT NULL,
24         FOREIGN KEY (parent) REFERENCES tree_node (id) ON DELETE CASCADE,
26         version INT NOT NULL,
27         FOREIGN KEY (version) REFERENCES tree_node_archive (id)
28 ) ENGINE=InnoDB;
31 # Board-related SGF node
32 # This should be used only for trivial SGF nodes; any metadata should be
33 # stored in proper table columns.
34 CREATE TABLE sgf_node (
35         id INT AUTO_INCREMENT PRIMARY KEY,
37         tnode INT NOT NULL,
38         FOREIGN KEY (tnode) REFERENCES tree_node_archive (id) ON DELETE CASCADE,
40         code VARCHAR(2) NOT NULL,
41         value TEXT NOT NULL
42 ) ENGINE=InnoDB;
45 INSERT INTO tree_node_archive SET editorial="The Road Begins Here";
46 INSERT INTO tree_node SET version=1;