remove use of rust in migration (#704)

* remove use of rust in migration

rewrite use_timelines_for_feed in pure sql
delete tantivy related migration. It will require reintroducing tantivy
initialisation in docs

fix #702

* Fill timeline from migrations

should fix #692 , but probably require some testing
This commit is contained in:
fdb-hiroshima 2019-12-14 21:06:07 +01:00 committed by Ana Gelez
parent 3bd2305115
commit 6c8944315a
10 changed files with 60 additions and 64 deletions

View File

@ -1,6 +0,0 @@
-- This file should undo anything in `up.sql`
--#!|_conn, path: &Path| {
--#! let mut pb = path.to_path_buf();
--#! pb.push("search_index");
--#! std::fs::remove_dir_all(pb).map_err(Error::from)
--#!}

View File

@ -1,10 +0,0 @@
-- Your SQL goes here
--#!|conn: &Connection, path: &Path| {
--#! use std::env::var;
--#! let mut pb = Path::new(&var("SEARCH_INDEX")
--#! .unwrap_or_else(|_|"search_index".to_owned())).to_path_buf();
--#! let searcher = super::search::Searcher::create(&pb)?;
--#! searcher.fill(conn)?;
--#! searcher.commit();
--#! Ok(())
--#!}

View File

@ -1,17 +1,6 @@
-- Your SQL goes here -- Your SQL goes here
--#!|conn: &Connection, path: &Path| { INSERT INTO timeline_definition (name, query) VALUES
--#! super::timeline::Timeline::new_for_instance(conn, "Local feed".into(), "local".into()).expect("Local feed creation error"); ('Local feed', 'local'),
--#! super::timeline::Timeline::new_for_instance(conn, "Federated feed".into(), "all".into()).expect("Federated feed creation error"); ('Federated feed', 'all');
--#! INSERT INTO timeline_definition (user_id,name,query)
--#! for i in 0.. { select id,'Your feed',CONCAT('followed or [',fqn,']') from users;
--#! if let Some(users) = super::users::User::get_local_page(conn, (i * 20, (i + 1) * 20)).ok().filter(|l| !l.is_empty()) {
--#! for u in users {
--#! super::timeline::Timeline::new_for_user(conn, u.id, "Your feed".into(), format!("followed or author in [ {} ]", u.fqn)).expect("User feed creation error");
--#! }
--#! } else {
--#! break;
--#! }
--#! }
--#!
--#! Ok(())
--#!}

View File

@ -0,0 +1,8 @@
DELETE FROM timeline WHERE id IN
(
SELECT timeline.id FROM timeline
INNER JOIN timeline_definition ON timeline.timeline_id = timeline_definition.id
WHERE timeline_definition.query LIKE 'followed or [%]' OR
timeline_definition.query = 'local' OR
timeline_definition.query = 'all'
);

View File

@ -0,0 +1,17 @@
INSERT INTO timeline (post_id, timeline_id)
SELECT posts.id,timeline_definition.id FROM posts,timeline_definition
WHERE timeline_definition.query = 'all';
INSERT INTO timeline (post_id, timeline_id)
SELECT posts.id,timeline_definition.id FROM posts,timeline_definition
INNER JOIN blogs ON posts.blog_id = blogs.id
INNER JOIN instances ON blogs.instance_id = instances.id
WHERE timeline_definition.query = 'local' and instances.local = true;
INSERT INTO timeline (post_id, timeline_id)
SELECT posts.id,timeline_definition.id FROM posts
INNER JOIN blog_authors ON posts.blog_id = blog_authors.blog_id
LEFT JOIN follows ON blog_authors.author_id = follows.following_id
INNER JOIN timeline_definition ON follows.follower_id = timeline_definition.user_id
or blog_authors.author_id = timeline_definition.user_id
WHERE timeline_definition.query LIKE 'followed or [%]';

View File

@ -1,6 +0,0 @@
-- This file should undo anything in `up.sql`
--#!|_conn, path: &Path| {
--#! let mut pb = path.to_path_buf();
--#! pb.push("search_index");
--#! std::fs::remove_dir_all(pb).map_err(Error::from)
--#!}

View File

@ -1,10 +0,0 @@
-- Your SQL goes here
--#!|conn: &Connection, path: &Path| {
--#! use std::env::var;
--#! let mut pb = Path::new(&var("SEARCH_INDEX")
--#! .unwrap_or_else(|_|"search_index".to_owned())).to_path_buf();
--#! let searcher = super::search::Searcher::create(&pb)?;
--#! searcher.fill(conn)?;
--#! searcher.commit();
--#! Ok(())
--#!}

View File

@ -1,17 +1,6 @@
-- Your SQL goes here -- Your SQL goes here
--#!|conn: &Connection, path: &Path| { INSERT INTO timeline_definition (name, query) VALUES
--#! super::timeline::Timeline::new_for_instance(conn, "Local feed".into(), "local".into()).expect("Local feed creation error"); ('Local feed', 'local'),
--#! super::timeline::Timeline::new_for_instance(conn, "Federated feed".into(), "all".into()).expect("Federated feed creation error"); ('Federated feed', 'all');
--#! INSERT INTO timeline_definition (user_id,name,query)
--#! for i in 0.. { select id,'Your feed','followed or ['||fqn||']' from users;
--#! if let Some(users) = super::users::User::get_local_page(conn, (i * 20, (i + 1) * 20)).ok().filter(|l| !l.is_empty()) {
--#! for u in users {
--#! super::timeline::Timeline::new_for_user(conn, u.id, "Your feed".into(), format!("followed or author in [ {} ]", u.fqn)).expect("User feed creation error");
--#! }
--#! } else {
--#! break;
--#! }
--#! }
--#!
--#! Ok(())
--#!}

View File

@ -0,0 +1,8 @@
DELETE FROM timeline WHERE id IN
(
SELECT timeline.id FROM timeline
INNER JOIN timeline_definition ON timeline.timeline_id = timeline_definition.id
WHERE timeline_definition.query LIKE 'followed or [%]' OR
timeline_definition.query = 'local' OR
timeline_definition.query = 'all'
);

View File

@ -0,0 +1,17 @@
INSERT INTO timeline (post_id, timeline_id)
SELECT posts.id,timeline_definition.id FROM posts,timeline_definition
WHERE timeline_definition.query = 'all';
INSERT INTO timeline (post_id, timeline_id)
SELECT posts.id,timeline_definition.id FROM posts,timeline_definition
INNER JOIN blogs ON posts.blog_id = blogs.id
INNER JOIN instances ON blogs.instance_id = instances.id
WHERE timeline_definition.query = 'local' and instances.local = true;
INSERT INTO timeline (post_id, timeline_id)
SELECT posts.id,timeline_definition.id FROM posts
INNER JOIN blog_authors ON posts.blog_id = blog_authors.blog_id
LEFT JOIN follows ON blog_authors.author_id = follows.following_id
INNER JOIN timeline_definition ON follows.follower_id = timeline_definition.user_id
or blog_authors.author_id = timeline_definition.user_id
WHERE timeline_definition.query LIKE 'followed or [%]';