2019-05-16 05:32:55 +02:00
|
|
|
|
|
|
|
PRAGMA FOREIGN_KEYS = ON;
|
|
|
|
|
2019-05-19 00:51:30 +02:00
|
|
|
-- tables
|
2019-05-19 08:24:20 +02:00
|
|
|
-- DROP TABLE IF EXISTS COMMENT;
|
|
|
|
-- DROP TABLE IF EXISTS CHANNEL;
|
|
|
|
|
2019-05-31 21:56:32 +02:00
|
|
|
-- DROP TABLE IF EXISTS COMMENT;
|
2019-05-16 05:32:55 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS COMMENT (
|
2019-05-19 00:51:30 +02:00
|
|
|
CommentId TEXT NOT NULL,
|
2019-05-16 05:32:55 +02:00
|
|
|
LbryClaimId TEXT NOT NULL,
|
2019-05-19 00:51:30 +02:00
|
|
|
ChannelId TEXT DEFAULT NULL,
|
2019-05-16 05:32:55 +02:00
|
|
|
Body TEXT NOT NULL,
|
2019-05-19 00:51:30 +02:00
|
|
|
ParentId TEXT DEFAULT NULL,
|
|
|
|
Signature TEXT DEFAULT NULL,
|
|
|
|
Timestamp INTEGER NOT NULL,
|
2019-06-11 02:24:06 +02:00
|
|
|
SigningTs TEXT DEFAULT NULL,
|
2019-05-19 00:51:30 +02:00
|
|
|
CONSTRAINT COMMENT_PRIMARY_KEY PRIMARY KEY (CommentId) ON CONFLICT IGNORE,
|
|
|
|
CONSTRAINT COMMENT_SIGNATURE_SK UNIQUE (Signature) ON CONFLICT ABORT,
|
|
|
|
CONSTRAINT COMMENT_CHANNEL_FK FOREIGN KEY (ChannelId) REFERENCES CHANNEL(ClaimId)
|
|
|
|
ON DELETE NO ACTION ON UPDATE NO ACTION,
|
2019-05-16 05:32:55 +02:00
|
|
|
CONSTRAINT COMMENT_PARENT_FK FOREIGN KEY (ParentId) REFERENCES COMMENT(CommentId)
|
2019-05-19 00:51:30 +02:00
|
|
|
ON UPDATE CASCADE ON DELETE NO ACTION -- setting null implies comment is top level
|
2019-05-16 05:32:55 +02:00
|
|
|
);
|
2019-05-19 00:51:30 +02:00
|
|
|
|
2019-06-11 02:24:06 +02:00
|
|
|
-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
2019-06-06 05:20:27 +02:00
|
|
|
|
2019-05-31 21:56:32 +02:00
|
|
|
-- DROP TABLE IF EXISTS CHANNEL;
|
2019-05-23 12:33:07 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS CHANNEL(
|
|
|
|
ClaimId TEXT NOT NULL,
|
|
|
|
Name TEXT NOT NULL,
|
|
|
|
CONSTRAINT CHANNEL_PK PRIMARY KEY (ClaimId)
|
|
|
|
ON CONFLICT IGNORE
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2019-05-19 00:51:30 +02:00
|
|
|
-- indexes
|
2019-05-21 13:28:21 +02:00
|
|
|
-- DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX;
|
|
|
|
CREATE INDEX IF NOT EXISTS COMMENT_CLAIM_INDEX ON COMMENT (LbryClaimId);
|
2019-05-19 00:51:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- VIEWS
|
2019-05-31 21:55:48 +02:00
|
|
|
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
2019-06-06 05:20:27 +02:00
|
|
|
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_url, signature, signing_ts, parent_id, comment) AS
|
|
|
|
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || CHAN.Name || '#' || CHAN.ClaimId, C.Signature, C.SigningTs, C.ParentId, C.Body
|
2019-05-31 21:55:48 +02:00
|
|
|
FROM COMMENT AS C
|
|
|
|
LEFT OUTER JOIN CHANNEL CHAN on C.ChannelId = CHAN.ClaimId
|
2019-06-01 04:05:12 +02:00
|
|
|
ORDER BY C.Timestamp DESC;
|
2019-05-19 00:51:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-31 21:56:32 +02:00
|
|
|
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
2019-05-21 13:28:21 +02:00
|
|
|
CREATE VIEW IF NOT EXISTS COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
2019-05-19 00:51:30 +02:00
|
|
|
SELECT AUTHOR.Name, OG.Body, PCHAN.Name, PARENT.Body FROM COMMENT AS OG
|
|
|
|
JOIN COMMENT AS PARENT
|
|
|
|
ON OG.ParentId = PARENT.CommentId
|
|
|
|
JOIN CHANNEL AS PCHAN ON PARENT.ChannelId = PCHAN.ClaimId
|
|
|
|
JOIN CHANNEL AS AUTHOR ON OG.ChannelId = AUTHOR.ClaimId
|
|
|
|
ORDER BY OG.Timestamp;
|
|
|
|
|
2019-05-19 08:24:20 +02:00
|
|
|
-- this is the default channel for anyone who wants to publish anonymously
|
2019-05-31 21:55:48 +02:00
|
|
|
-- INSERT INTO CHANNEL
|
|
|
|
-- VALUES ('9cb713f01bf247a0e03170b5ed00d5161340c486', '@Anonymous');
|