account based feeds
[rss-reader.git] / sql / seed.ts
index 46af5a41b17510b5972f395377b689767b5ae495..bf0118c53df3f699f01a0820a8e3b6743f9c6342 100644 (file)
@@ -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);