X-Git-Url: https://git.xangelo.ca/?p=rss-reader.git;a=blobdiff_plain;f=sql%2Fseed.ts;fp=sql%2Fseed.ts;h=bf0118c53df3f699f01a0820a8e3b6743f9c6342;hp=46af5a41b17510b5972f395377b689767b5ae495;hb=200808f1fc03c8669968a77074bc6051d3bf663b;hpb=1efc77a5994e43c58f326016acfe9e48da055b56 diff --git a/sql/seed.ts b/sql/seed.ts index 46af5a4..bf0118c 100644 --- a/sql/seed.ts +++ b/sql/seed.ts @@ -1,24 +1,39 @@ import Database from 'better-sqlite3'; -import {RSSParser} from 'src/parsers/rss'; -import { v4 as uuidv4 } from 'uuid'; +import { cli } from './migrate'; const DB = 'feeds.db'; export const writer = new Database(DB, { verbose: console.log }); +export function down() { + writer.prepare('drop table feed_items').run(); + writer.prepare('drop table feedlist').run(); + writer.prepare('drop table accounts').run(); +} + +export function up() { + writer.prepare(` + create table accounts ( + id text unique, + email text unique, + signup_date number, + login_code text, + login_code_expires number + ) + `).run(); -writer.prepare('drop table if exists feed_items').run(); -writer.prepare('drop table feedlist').run(); writer.prepare(` create table feedlist ( id text unique, + account_id text, title text, - link text unique + link text ) `).run(); +writer.prepare(`create index idx_account_feed on feedlist (account_id, link)`).run(); writer.prepare(` @@ -34,7 +49,9 @@ writer.prepare(` ) `).run(); +} +/* const feeds = [ { id: uuidv4(), @@ -68,3 +85,17 @@ feeds.forEach(async feed => { insert.run(id, feed.id, item.guid, item.title, item.link, item.pubDate, item.content); }); }); +*/ +const args = cli(process.argv); +if(args.dir === 'up') { + up(); +} +else if(args.dir === 'down') { + down(); +} +else { + console.error('Invalid dir'); + process.exit(1); +} + +process.exit(0);