X-Git-Url: http://git.hcoop.net/hcoop/zz_old/portal.git/blobdiff_plain/3ad30cf65673b36d3adb0725693c25310b9e1040..ef48ed9eaeea982b8580c44c0027edff6abde4d8:/tables.sql

diff --git a/tables.sql b/tables.sql
index 97a890c..ea3633c 100644
--- a/tables.sql
+++ b/tables.sql
@@ -35,6 +35,7 @@ CREATE TABLE WebUser(
 	bal INTEGER NOT NULL,
 	joined TIMESTAMP NOT NULL,
 	app INTEGER NOT NULL,
+	shares INTEGER NOT NULL,
 	FOREIGN KEY (bal) REFERENCES Balance(id) ON DELETE CASCADE,
 	FOREIGN KEY (app) REFERENCES MemberApp(id) ON DELETE CASCADE);
 
@@ -180,6 +181,8 @@ CREATE TABLE SupIssue(
 	priv BOOLEAN NOT NULL,
 	status INTEGER NOT NULL,
 	stamp TIMESTAMP NOT NULL,
+	pstamp TIMESTAMP,
+	cstamp TIMESTAMP,
 	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE,
 	FOREIGN KEY (cat) REFERENCES SupCategory(id) ON DELETE CASCADE);
 
@@ -203,14 +206,30 @@ CREATE TABLE SupSubscription(
 	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE,
 	FOREIGN KEY (cat) REFERENCES SupCategory(id) ON DELETE CASCADE);
 
+CREATE TABLE WebNode(
+	id INTEGER PRIMARY KEY,
+	name TEXT NOT NULL,
+	descr TEXT NOT NULL,
+	debian TEXT NOT NULL);
+
+INSERT INTO WebNode (id, name, descr, debian)
+	VALUES (0, 'fyodor', 'old server', 'testing');
+INSERT INTO WebNode (id, name, descr, debian)
+	VALUES (1, 'deleuze', 'main server', 'stable');
+INSERT INTO WebNode (id, name, descr, debian)
+	VALUES (2, 'mire', 'member web server', 'stable');
+
 CREATE TABLE Apt(
 	id INTEGER PRIMARY KEY,
 	usr INTEGER NOT NULL,
+	node INTEGER NOT NULL,
 	data TEXT NOT NULL,
 	msg TEXT NOT NULL,
 	status INTEGER NOT NULL,
 	stamp TIMESTAMP NOT NULL,
-	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE);
+	cstamp TIMESTAMP,
+	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE,
+	FOREIGN KEY (node) REFERENCES WebNode(id) ON DELETE CASCADE);
 
 CREATE SEQUENCE AptSeq START 1;
 
@@ -221,6 +240,7 @@ CREATE TABLE Domain(
 	msg TEXT NOT NULL,
 	status INTEGER NOT NULL,
 	stamp TIMESTAMP NOT NULL,
+	cstamp TIMESTAMP,
 	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE);
 
 CREATE SEQUENCE DomainSeq START 1;
@@ -232,6 +252,7 @@ CREATE TABLE MailingList(
 	msg TEXT NOT NULL,
 	status INTEGER NOT NULL,
 	stamp TIMESTAMP NOT NULL,
+	cstamp TIMESTAMP,
 	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE);
 
 CREATE SEQUENCE MailingListSeq START 1;
@@ -247,8 +268,16 @@ CREATE TABLE AppVote(
 	FOREIGN KEY (app) REFERENCES MemberApp(id) ON DELETE CASCADE,
 	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE);
 
+CREATE VIEW WebUserPaying
+	AS SELECT id, name, rname, bal, joined, app, shares
+		FROM WebUser
+			JOIN (SELECT usr FROM Membership JOIN WebGroup
+				ON grp = WebGroup.id
+					AND WebGroup.name = 'paying') AS bob
+				ON usr = WebUser.id;
+
 CREATE VIEW WebUserActive
-	AS SELECT id, name, rname, bal, joined, app
+	AS SELECT id, name, rname, bal, joined, app, shares
 		FROM WebUser
 			LEFT OUTER JOIN (SELECT usr FROM Membership JOIN WebGroup
 				ON grp = WebGroup.id AND (WebGroup.name IN ('retired', 'phantom'))) AS mem
@@ -275,10 +304,13 @@ CREATE TABLE RollCallEntry(
 CREATE TABLE Sec(
 	id INTEGER PRIMARY KEY,
 	usr INTEGER NOT NULL,
+	node INTEGER NOT NULL,
 	data TEXT NOT NULL,
 	msg TEXT NOT NULL,
 	status INTEGER NOT NULL,
 	stamp TIMESTAMP NOT NULL,
-	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE);
+	cstamp TIMESTAMP,
+	FOREIGN KEY (usr) REFERENCES WebUser(id) ON DELETE CASCADE,
+	FOREIGN KEY (node) REFERENCES WebNode(id) ON DELETE CASCADE);
 
 CREATE SEQUENCE SecSeq START 1;
