BEGIN TRANSACTION;
CREATE TABLE "quotes" (
	"id"	INTEGER,
	"source"	INTEGER NOT NULL,
	"time"	INTEGER NOT NULL,
	"text"	TEXT NOT NULL,
	"text_zh"	INTEGER,
	FOREIGN KEY("source") REFERENCES "sources"("id") ON DELETE CASCADE ON UPDATE CASCADE,
	PRIMARY KEY("id" AUTOINCREMENT)
);
CREATE TABLE "sources" (
	"id"	INTEGER,
	"type"	INTEGER NOT NULL,
	"title"	TEXT NOT NULL,
	"title_zh"	TEXT,
	PRIMARY KEY("id" AUTOINCREMENT)
);
CREATE VIEW "v_random_quote" AS
SELECT
	sources.title,
	sources.title_zh,
	text,
	text_zh
FROM quotes
INNER JOIN sources ON sources.id = quotes.source
ORDER BY RANDOM()
LIMIT 1;
COMMIT;
