messenger_postgresql.sql 6.31 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5 6 7
-- $RCSfile$
-- $Revision$
-- $Date$

-- Note: This schema has only been tested on PostgreSQL 7.3.2.

CREATE TABLE jiveUser (
Matt Tucker's avatar
Matt Tucker committed
8
  username              VARCHAR(32)     NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
9 10 11 12 13
  password              VARCHAR(32)     NOT NULL,
  name                  VARCHAR(100),
  email                 VARCHAR(100),
  creationDate          CHAR(15)        NOT NULL,
  modificationDate      CHAR(15)        NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
14
  CONSTRAINT jiveUser_pk PRIMARY KEY (username)
Matt Tucker's avatar
Matt Tucker committed
15 16 17 18 19
);
CREATE INDEX jiveUser_cDate_idx ON jiveUser (creationDate);


CREATE TABLE jiveUserProp (
Matt Tucker's avatar
Matt Tucker committed
20
  username              VARCHAR(32)     NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
21 22
  name                  VARCHAR(100)    NOT NULL,
  propValue             TEXT            NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
23
  CONSTRAINT jiveUserProp_pk PRIMARY KEY (username, name)
Matt Tucker's avatar
Matt Tucker committed
24 25 26 27
);


CREATE TABLE jivePrivate (
Matt Tucker's avatar
Matt Tucker committed
28
  username              VARCHAR(32)     NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
29 30 31
  name                  VARCHAR(100)    NOT NULL,
  namespace             VARCHAR(200)    NOT NULL,
  value                 TEXT            NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
32
  CONSTRAINT jivePrivate_pk PRIMARY KEY (username, name, namespace)
Matt Tucker's avatar
Matt Tucker committed
33 34 35 36
);


CREATE TABLE jiveOffline (
Matt Tucker's avatar
Matt Tucker committed
37
  username              VARCHAR(32)     NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
38 39 40 41
  messageID             INTEGER         NOT NULL,
  creationDate          CHAR(15)        NOT NULL,
  messageSize           INTEGER         NOT NULL,
  message               LONG            NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
42
  CONSTRAINT jiveOffline_pk PRIMARY KEY (username, messageID)
Matt Tucker's avatar
Matt Tucker committed
43 44 45 46 47
);


CREATE TABLE jiveRoster (
  rosterID              INTEGER         NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
48 49
  username              VARCHAR(32)     NOT NULL,
  jid                   VARCHAR(1024)   NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
50 51 52 53 54 55
  sub                   INTEGER         NOT NULL,
  ask                   INTEGER         NOT NULL,
  recv                  INTEGER         NOT NULL,
  nick                  VARCHAR(255),
  CONSTRAINT jiveRoster_pk PRIMARY KEY (rosterID)
);
Matt Tucker's avatar
Matt Tucker committed
56
CREATE INDEX jiveRoster_username_idx ON jiveRoster (username);
Matt Tucker's avatar
Matt Tucker committed
57 58 59 60 61 62 63 64 65 66 67 68 69


CREATE TABLE jiveRosterGroups (
  rosterID              INTEGER         NOT NULL,
  rank                  INTEGER         NOT NULL,
  groupName             VARCHAR(255)    NOT NULL,
  CONSTRAINT jiveRosterGroups_pk PRIMARY KEY (rosterID, rank)
);
CREATE INDEX jiveRosterGroups_rosterID_idx ON jiveRosterGroups (rosterID);
ALTER TABLE jiveRosterGroups ADD CONSTRAINT jiveRosterGroups_rosterID_fk FOREIGN KEY (rosterID) REFERENCES jiveRoster INITIALLY DEFERRED DEFERRABLE;


CREATE TABLE jiveVCard (
Matt Tucker's avatar
Matt Tucker committed
70
  username              VARCHAR(32)     NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
71 72
  name                  VARCHAR(100)    NOT NULL,
  propValue             TEXT            NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
73
  CONSTRAINT jiveVCard_pk PRIMARY KEY (username, name)
Matt Tucker's avatar
Matt Tucker committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
);


CREATE TABLE jiveGroup (
  groupID               INTEGER         NOT NULL,
  name                  VARCHAR(50)     NOT NULL,
  description           VARCHAR(255),
  creationDate          CHAR(15)        NOT NULL,
  modificationDate      CHAR(15)        NOT NULL,
  CONSTRAINT jiveGroup_pk PRIMARY KEY (groupID)
);
CREATE INDEX jiveGroup_cDate_idx ON jiveGroup (creationDate);
CREATE INDEX jiveGroup_name_idx ON jiveGroup (name);


CREATE TABLE jiveGroupProp (
  groupID               INTEGER         NOT NULL,
  name                  VARCHAR(100)    NOT NULL,
  propValue             TEXT            NOT NULL,
  CONSTRAINT jiveGroupProp_pk PRIMARY KEY (groupID, name)
);
-- Commented out since this will cause a third party user system to break
-- If you do not use a third part user system, uncomment these constraints
-- ALTER TABLE jiveGroupProp ADD CONSTRAINT jiveGroupProp_groupID_fk FOREIGN KEY (groupID) REFERENCES jiveGroup INITIALLY DEFERRED DEFERRABLE;


CREATE TABLE jiveGroupUser (
  groupID               INTEGER         NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
102
  username              VARCHAR(32)     NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
103
  administrator         INTEGER         NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
104
  CONSTRAINT jiveGroupUser_pk PRIMARY KEY (groupID, username, administrator)
Matt Tucker's avatar
Matt Tucker committed
105
);
Matt Tucker's avatar
Matt Tucker committed
106
 
Matt Tucker's avatar
Matt Tucker committed
107 108 109 110 111 112 113

CREATE TABLE jiveID (
  idType                INTEGER         NOT NULL,
  id                    INTEGER         NOT NULL,
  CONSTRAINT jiveID_pk PRIMARY KEY (idType)
);

114 115 116 117 118 119
CREATE TABLE jiveProperty (
  name        VARCHAR(100) NOT NULL,
  propValue   VARCHAR(4000) NOT NULL,
  CONSTRAINT jiveProperty_pk PRIMARY KEY (name)
);

Gaston Dombiak's avatar
Gaston Dombiak committed
120 121 122 123
-- MUC Tables

CREATE TABLE mucRoom (
  roomID              INTEGER       NOT NULL,
124 125
  creationDate        CHAR(15)      NOT NULL,
  modificationDate    CHAR(15)      NOT NULL,
126
  name                VARCHAR(50)   NOT NULL,
127
  naturalName         VARCHAR(255)  NOT NULL,
Gaston Dombiak's avatar
Gaston Dombiak committed
128 129 130 131 132 133 134 135 136 137 138 139
  description         VARCHAR(255),
  canChangeSubject    INTEGER       NOT NULL,
  maxUsers            INTEGER       NOT NULL,
  publicRoom          INTEGER       NOT NULL,
  moderated           INTEGER       NOT NULL,
  invitationRequired  INTEGER       NOT NULL,
  canInvite           INTEGER       NOT NULL,
  password            VARCHAR(50)   NULL,
  canDiscoverJID      INTEGER       NOT NULL,
  logEnabled          INTEGER       NOT NULL,
  subject             VARCHAR(100)  NULL,
  rolesToBroadcast    INTEGER       NOT NULL,
140
  lastActiveDate      CHAR(15)      NULL,
Gaston Dombiak's avatar
Gaston Dombiak committed
141 142 143 144 145 146 147 148
  inMemory            INTEGER       NOT NULL,
  CONSTRAINT mucRoom__pk PRIMARY KEY (name)
);

CREATE INDEX mucRoom_roomID_idx ON mucRoom(roomID);

CREATE TABLE mucAffiliation (
  roomID              INTEGER        NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
149
  jid                 VARCHAR(1024)  NOT NULL,
Gaston Dombiak's avatar
Gaston Dombiak committed
150 151 152 153 154 155
  affiliation         INTEGER        NOT NULL,
  CONSTRAINT mucAffiliation__pk PRIMARY KEY (roomID,jid)
);

CREATE TABLE mucMember (
  roomID              INTEGER        NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
156
  jid                 VARCH(1024)    NOT NULL,
Gaston Dombiak's avatar
Gaston Dombiak committed
157 158 159 160 161 162
  nickname            VARCHAR(255)   NULL,
  CONSTRAINT mucMember__pk PRIMARY KEY (roomID,jid)
);

CREATE TABLE mucConversationLog (
  roomID              INTEGER        NOT NULL,
Matt Tucker's avatar
Matt Tucker committed
163
  sender              VARCHAR(1024)  NOT NULL,
Gaston Dombiak's avatar
Gaston Dombiak committed
164 165 166 167 168
  nickname            VARCHAR(255)   NULL,
  time                CHAR(15)       NOT NULL,
  subject             VARCHAR(255)   NULL,
  body                TEXT           NULL
);
Matt Tucker's avatar
Matt Tucker committed
169 170 171 172 173 174

-- Finally, insert default table values.

-- Unique ID entry for user, group   
-- The User ID entry starts at 2 (after admin user entry).  
INSERT INTO jiveID (idType, id) VALUES (3, 2);
Matt Tucker's avatar
Matt Tucker committed
175
INSERT INTO jiveID (idType, id) VALUES (4, 1);
Matt Tucker's avatar
Matt Tucker committed
176 177 178 179
INSERT INTO jiveID (idType, id) VALUES (18, 1);
INSERT INTO jiveID (idType, id) VALUES (19, 1);
INSERT INTO jiveID (idType, id) VALUES (23, 1);

Matt Tucker's avatar
Matt Tucker committed
180 181 182
-- Entry for admin user
INSERT INTO jiveUser (username, password, name, email, creationDate, modificationDate)
    VALUES ('admin', 'admin', 'Administrator', 'admin@example.com', '0', '0');