| 1 | -- |
|---|
| 2 | -- Tigase Jabber/XMPP Server |
|---|
| 3 | -- Copyright (C) 2004-2007 "Artur Hefczyc" <artur.hefczyc@tigase.org> |
|---|
| 4 | -- |
|---|
| 5 | -- This program is free software: you can redistribute it and/or modify |
|---|
| 6 | -- it under the terms of the GNU General Public License as published by |
|---|
| 7 | -- the Free Software Foundation, either version 3 of the License. |
|---|
| 8 | -- |
|---|
| 9 | -- This program is distributed in the hope that it will be useful, |
|---|
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | -- GNU General Public License for more details. |
|---|
| 13 | -- |
|---|
| 14 | -- You should have received a copy of the GNU General Public License |
|---|
| 15 | -- along with this program. Look for COPYING file in the top folder. |
|---|
| 16 | -- If not, see http://www.gnu.org/licenses/. |
|---|
| 17 | -- |
|---|
| 18 | -- $Rev: $ |
|---|
| 19 | -- Last modified by $Author: $ |
|---|
| 20 | -- $Date: $ |
|---|
| 21 | -- |
|---|
| 22 | |
|---|
| 23 | -- To load schema to MySQL database execute following commands: |
|---|
| 24 | -- |
|---|
| 25 | -- mysqladmin -u root -pdbpass create tigase |
|---|
| 26 | -- mysql -u root -pdbpass tigase < database/mysql-schema.sql |
|---|
| 27 | -- echo "GRANT ALL ON tigase.* TO tigase_user@'%' \ |
|---|
| 28 | -- IDENTIFIED BY 'tigase_passwd'; \ |
|---|
| 29 | -- FLUSH PRIVILEGES;" | mysql -u root -pdbpass mysql |
|---|
| 30 | -- echo "GRANT ALL ON tigase.* TO tigase_user@'localhost' \ |
|---|
| 31 | -- IDENTIFIED BY 'tigase_passwd'; \ |
|---|
| 32 | -- FLUSH PRIVILEGES;" | mysql -u root -pdbpass mysql |
|---|
| 33 | -- echo "GRANT ALL ON tigase.* TO tigase_user \ |
|---|
| 34 | -- IDENTIFIED BY 'tigase_passwd'; \ |
|---|
| 35 | -- FLUSH PRIVILEGES;" | mysql -u root -pdbpass mysql |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | create table short_news ( |
|---|
| 39 | -- Automatic record ID |
|---|
| 40 | snid bigint unsigned NOT NULL auto_increment, |
|---|
| 41 | -- Automaticly generated timestamp and automaticly updated on change |
|---|
| 42 | publishing_time timestamp, |
|---|
| 43 | -- Optional news type: 'shorts', 'minis', 'techs', 'funs'.... |
|---|
| 44 | news_type varchar(10), |
|---|
| 45 | -- Author JID |
|---|
| 46 | author varchar(128) NOT NULL, |
|---|
| 47 | -- Short subject - this is short news, right? |
|---|
| 48 | subject varchar(128) NOT NULL, |
|---|
| 49 | -- Short news message - this is short news, right? |
|---|
| 50 | body varchar(1024) NOT NULL, |
|---|
| 51 | primary key(snid), |
|---|
| 52 | key publishing_time (publishing_time), |
|---|
| 53 | key author (author), |
|---|
| 54 | key news_type (news_type) |
|---|
| 55 | ) |
|---|
| 56 | ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC; |
|---|
| 57 | |
|---|
| 58 | create table xmpp_stanza ( |
|---|
| 59 | id bigint unsigned NOT NULL auto_increment, |
|---|
| 60 | stanza text NOT NULL, |
|---|
| 61 | |
|---|
| 62 | primary key (id) |
|---|
| 63 | ) |
|---|
| 64 | ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC; |
|---|
| 65 | |
|---|
| 66 | create table tig_users ( |
|---|
| 67 | uid bigint unsigned NOT NULL, |
|---|
| 68 | |
|---|
| 69 | user_id varchar(128) NOT NULL, |
|---|
| 70 | |
|---|
| 71 | primary key (uid), |
|---|
| 72 | unique key user_id (user_id) |
|---|
| 73 | ) |
|---|
| 74 | ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC; |
|---|
| 75 | |
|---|
| 76 | create table tig_nodes ( |
|---|
| 77 | nid bigint unsigned NOT NULL, |
|---|
| 78 | parent_nid bigint unsigned, |
|---|
| 79 | uid bigint unsigned NOT NULL, |
|---|
| 80 | |
|---|
| 81 | node varchar(64) NOT NULL, |
|---|
| 82 | |
|---|
| 83 | primary key (nid), |
|---|
| 84 | unique key tnode (parent_nid, uid, node), |
|---|
| 85 | key node (node), |
|---|
| 86 | constraint tig_nodes_constr foreign key (uid) references tig_users (uid) |
|---|
| 87 | ) |
|---|
| 88 | ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC; |
|---|
| 89 | |
|---|
| 90 | create table tig_pairs ( |
|---|
| 91 | nid bigint unsigned, |
|---|
| 92 | uid bigint unsigned NOT NULL, |
|---|
| 93 | |
|---|
| 94 | pkey varchar(128) NOT NULL, |
|---|
| 95 | pval varchar(65535), |
|---|
| 96 | |
|---|
| 97 | key pkey (pkey), |
|---|
| 98 | constraint tig_pairs_constr_1 foreign key (uid) references tig_users (uid), |
|---|
| 99 | constraint tig_pairs_constr_2 foreign key (nid) references tig_nodes (nid) |
|---|
| 100 | ) |
|---|
| 101 | ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC; |
|---|
| 102 | |
|---|
| 103 | -- create table tig_max_ids ( |
|---|
| 104 | -- max_uid bigint unsigned, |
|---|
| 105 | -- max_nid bigint unsigned |
|---|
| 106 | -- ) |
|---|
| 107 | -- ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC; |
|---|
| 108 | |
|---|
| 109 | -- insert into tig_max_ids (max_uid, max_nid) values (1, 1); |
|---|
| 110 | |
|---|
| 111 | -- Get top nodes for the user: user1@hostname |
|---|
| 112 | -- |
|---|
| 113 | -- select nid, node from nodes, users |
|---|
| 114 | -- where ('user1@hostname' = user_id) |
|---|
| 115 | -- AND (nodes.uid = users.uid) |
|---|
| 116 | -- AND (parent_nid is null); |
|---|
| 117 | |
|---|
| 118 | -- Get all subnodes of the node: /privacy/default for user: user1@hostname |
|---|
| 119 | -- |
|---|
| 120 | -- select nid, node from nodes, |
|---|
| 121 | -- ( |
|---|
| 122 | -- select nid as dnid from nodes, |
|---|
| 123 | -- ( |
|---|
| 124 | -- select nid as pnid from nodes, users |
|---|
| 125 | -- where ('user1@hostname' = user_id) |
|---|
| 126 | -- AND (nodes.uid = users.uid) |
|---|
| 127 | -- AND (parent_nid is null) |
|---|
| 128 | -- AND (node = 'privacy') |
|---|
| 129 | -- ) ptab where (parent_nid = pnid) |
|---|
| 130 | -- AND (node = 'default') |
|---|
| 131 | -- ) dtab where (parent_nid = dnid); |
|---|
| 132 | |
|---|
| 133 | -- Get all keys (pairs) for the node: /privacy/default/24 for user: user1@hostname |
|---|
| 134 | -- |
|---|
| 135 | -- select pkey, pval from pairs, |
|---|
| 136 | -- ( |
|---|
| 137 | -- select nid, node from nodes, |
|---|
| 138 | -- ( |
|---|
| 139 | -- select nid as dnid from nodes, |
|---|
| 140 | -- ( |
|---|
| 141 | -- select nid as pnid from nodes, users |
|---|
| 142 | -- where ('user1@hostname' = user_id) |
|---|
| 143 | -- AND (nodes.uid = users.uid) |
|---|
| 144 | -- AND (parent_nid is null) |
|---|
| 145 | -- AND (node = 'privacy') |
|---|
| 146 | -- ) ptab where (parent_nid = pnid) |
|---|
| 147 | -- AND (node = 'default') |
|---|
| 148 | -- ) dtab where (parent_nid = dnid) |
|---|
| 149 | -- ) ntab where (pairs.nid = ntab.nid) AND (node = '24'); |
|---|