Reformats code
This commit is contained in:
parent
c9996fd658
commit
35c95a0037
5 changed files with 43 additions and 33 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
PRAGMA FOREIGN_KEYS = ON;
|
PRAGMA FOREIGN_KEYS = ON;
|
||||||
|
|
||||||
-- tables
|
-- tables
|
||||||
|
@ -6,7 +5,8 @@ PRAGMA FOREIGN_KEYS = ON;
|
||||||
-- DROP TABLE IF EXISTS CHANNEL;
|
-- DROP TABLE IF EXISTS CHANNEL;
|
||||||
|
|
||||||
-- DROP TABLE IF EXISTS COMMENT;
|
-- DROP TABLE IF EXISTS COMMENT;
|
||||||
CREATE TABLE IF NOT EXISTS COMMENT (
|
CREATE TABLE IF NOT EXISTS COMMENT
|
||||||
|
(
|
||||||
CommentId TEXT NOT NULL,
|
CommentId TEXT NOT NULL,
|
||||||
LbryClaimId TEXT NOT NULL,
|
LbryClaimId TEXT NOT NULL,
|
||||||
ChannelId TEXT DEFAULT NULL,
|
ChannelId TEXT DEFAULT NULL,
|
||||||
|
@ -26,7 +26,8 @@ CREATE TABLE IF NOT EXISTS COMMENT (
|
||||||
-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
||||||
|
|
||||||
-- DROP TABLE IF EXISTS CHANNEL;
|
-- DROP TABLE IF EXISTS CHANNEL;
|
||||||
CREATE TABLE IF NOT EXISTS CHANNEL(
|
CREATE TABLE IF NOT EXISTS CHANNEL
|
||||||
|
(
|
||||||
ClaimId TEXT NOT NULL,
|
ClaimId TEXT NOT NULL,
|
||||||
Name TEXT NOT NULL,
|
Name TEXT NOT NULL,
|
||||||
CONSTRAINT CHANNEL_PK PRIMARY KEY (ClaimId)
|
CONSTRAINT CHANNEL_PK PRIMARY KEY (ClaimId)
|
||||||
|
@ -42,8 +43,18 @@ CREATE INDEX IF NOT EXISTS CHANNEL_COMMENT_INDEX ON COMMENT(ChannelId, CommentId
|
||||||
|
|
||||||
-- VIEWS
|
-- VIEWS
|
||||||
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
||||||
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
|
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_url,
|
||||||
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || CHAN.Name || '#' || CHAN.ClaimId, C.Signature, C.SigningTs, C.ParentId, C.Body
|
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
|
||||||
FROM COMMENT AS C
|
FROM COMMENT AS C
|
||||||
LEFT OUTER JOIN CHANNEL CHAN on C.ChannelId = CHAN.ClaimId
|
LEFT OUTER JOIN CHANNEL CHAN on C.ChannelId = CHAN.ClaimId
|
||||||
ORDER BY C.Timestamp DESC;
|
ORDER BY C.Timestamp DESC;
|
||||||
|
@ -52,7 +63,8 @@ CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, c
|
||||||
|
|
||||||
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
||||||
CREATE VIEW IF NOT EXISTS COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
CREATE VIEW IF NOT EXISTS COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
||||||
SELECT AUTHOR.Name, OG.Body, PCHAN.Name, PARENT.Body FROM COMMENT AS OG
|
SELECT AUTHOR.Name, OG.Body, PCHAN.Name, PARENT.Body
|
||||||
|
FROM COMMENT AS OG
|
||||||
JOIN COMMENT AS PARENT
|
JOIN COMMENT AS PARENT
|
||||||
ON OG.ParentId = PARENT.CommentId
|
ON OG.ParentId = PARENT.CommentId
|
||||||
JOIN CHANNEL AS PCHAN ON PARENT.ChannelId = PCHAN.ClaimId
|
JOIN CHANNEL AS PCHAN ON PARENT.ChannelId = PCHAN.ClaimId
|
||||||
|
|
|
@ -17,7 +17,6 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def setup_db_schema(app):
|
async def setup_db_schema(app):
|
||||||
|
|
||||||
if not pathlib.Path(app['db_path']).exists():
|
if not pathlib.Path(app['db_path']).exists():
|
||||||
logger.info('Setting up schema in %s', app['db_path'])
|
logger.info('Setting up schema in %s', app['db_path'])
|
||||||
setup_database(app['db_path'], app['config']['PATH']['SCHEMA'])
|
setup_database(app['db_path'], app['config']['PATH']['SCHEMA'])
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
root_dir = pathlib.Path(__file__).parent.parent
|
root_dir = pathlib.Path(__file__).parent.parent
|
||||||
config_path = root_dir / 'config' / 'conf.json'
|
config_path = root_dir / 'config' / 'conf.json'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue