diff options
author | citrons <citrons> | 2021-07-11 03:39:15 +0000 |
---|---|---|
committer | citrons <citrons> | 2021-07-11 03:39:15 +0000 |
commit | 183061d9a17e3613db2063ccd291af3fac904f11 (patch) | |
tree | b465e064566cac6803e1993bbc6a1ec808c4c490 /apioforum/db.py | |
parent | 8d2d7a54ee496224061d03bd81432688b14c1eb3 (diff) | |
parent | 4bb33e0c18b45ae0cc0f87438c8e0432cf6250c1 (diff) |
merge looks good
Diffstat (limited to 'apioforum/db.py')
-rw-r--r-- | apioforum/db.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/apioforum/db.py b/apioforum/db.py index 25bda94..97bd0e2 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -115,7 +115,42 @@ ALTER TABLE posts ADD COLUMN vote INTEGER REFERENCES votes(id); CREATE VIEW vote_counts AS SELECT poll, option_idx, count(*) AS num FROM votes WHERE current GROUP BY option_idx,poll; """, - +""" +CREATE TABLE forums ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + parent INTEGER REFERENCES forums(id), + description TEXT +); +INSERT INTO forums (name,parent,description) values ('apioforum',null, + 'welcome to the apioforum\n\n' || + 'forum rules: do not be a bad person. do not do bad things.'); + +PRAGMA foreign_keys = off; +BEGIN TRANSACTION; +CREATE TABLE threads_new ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL, + creator TEXT NOT NULL, + created TIMESTAMP NOT NULL, + updated TIMESTAMP NOT NULL, + forum NOT NULL REFERENCES forums(id), + poll INTEGER REFERENCES polls(id) +); +INSERT INTO threads_new (id,title,creator,created,updated,forum) + SELECT id,title,creator,created,updated,1 FROM threads; +DROP TABLE threads; +ALTER TABLE threads_new RENAME TO threads; +COMMIT; +PRAGMA foreign_keys = on; +""", +""" +CREATE VIEW most_recent_posts AS + SELECT max(id), * FROM posts GROUP BY thread; + +CREATE VIEW number_of_posts AS + SELECT thread, count(*) AS num_replies FROM posts GROUP BY thread; +""", ] def init_db(): |