From 6c8944315a826d4ca4b92a3c7f5a21a0555c0c06 Mon Sep 17 00:00:00 2001 From: fdb-hiroshima <35889323+fdb-hiroshima@users.noreply.github.com> Date: Sat, 14 Dec 2019 21:06:07 +0100 Subject: [PATCH] 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 --- .../down.sql | 6 ------ .../up.sql | 10 --------- .../up.sql | 21 +++++-------------- .../2019-12-10-104935_fill_timelines/down.sql | 8 +++++++ .../2019-12-10-104935_fill_timelines/up.sql | 17 +++++++++++++++ .../down.sql | 6 ------ .../up.sql | 10 --------- .../up.sql | 21 +++++-------------- .../2019-12-10-104935_fill_timelines/down.sql | 8 +++++++ .../2019-12-10-104935_fill_timelines/up.sql | 17 +++++++++++++++ 10 files changed, 60 insertions(+), 64 deletions(-) delete mode 100644 migrations/postgres/2019-04-28-201506_create_tantivy_index/down.sql delete mode 100644 migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql create mode 100644 migrations/postgres/2019-12-10-104935_fill_timelines/down.sql create mode 100644 migrations/postgres/2019-12-10-104935_fill_timelines/up.sql delete mode 100644 migrations/sqlite/2019-04-28-201506_create_tantivy_index/down.sql delete mode 100644 migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql create mode 100644 migrations/sqlite/2019-12-10-104935_fill_timelines/down.sql create mode 100644 migrations/sqlite/2019-12-10-104935_fill_timelines/up.sql diff --git a/migrations/postgres/2019-04-28-201506_create_tantivy_index/down.sql b/migrations/postgres/2019-04-28-201506_create_tantivy_index/down.sql deleted file mode 100644 index 41b20eb3..00000000 --- a/migrations/postgres/2019-04-28-201506_create_tantivy_index/down.sql +++ /dev/null @@ -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) ---#!} diff --git a/migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql b/migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql deleted file mode 100644 index 9d331b4e..00000000 --- a/migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql +++ /dev/null @@ -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(()) ---#!} diff --git a/migrations/postgres/2019-06-24-101212_use_timelines_for_feed/up.sql b/migrations/postgres/2019-06-24-101212_use_timelines_for_feed/up.sql index 96ece8c8..26e42c6f 100644 --- a/migrations/postgres/2019-06-24-101212_use_timelines_for_feed/up.sql +++ b/migrations/postgres/2019-06-24-101212_use_timelines_for_feed/up.sql @@ -1,17 +1,6 @@ -- Your SQL goes here ---#!|conn: &Connection, path: &Path| { ---#! super::timeline::Timeline::new_for_instance(conn, "Local feed".into(), "local".into()).expect("Local feed creation error"); ---#! super::timeline::Timeline::new_for_instance(conn, "Federated feed".into(), "all".into()).expect("Federated feed creation error"); ---#! ---#! for i in 0.. { ---#! 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(()) ---#!} +INSERT INTO timeline_definition (name, query) VALUES + ('Local feed', 'local'), + ('Federated feed', 'all'); +INSERT INTO timeline_definition (user_id,name,query) + select id,'Your feed',CONCAT('followed or [',fqn,']') from users; diff --git a/migrations/postgres/2019-12-10-104935_fill_timelines/down.sql b/migrations/postgres/2019-12-10-104935_fill_timelines/down.sql new file mode 100644 index 00000000..a1708a46 --- /dev/null +++ b/migrations/postgres/2019-12-10-104935_fill_timelines/down.sql @@ -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' + ); diff --git a/migrations/postgres/2019-12-10-104935_fill_timelines/up.sql b/migrations/postgres/2019-12-10-104935_fill_timelines/up.sql new file mode 100644 index 00000000..cfe780f0 --- /dev/null +++ b/migrations/postgres/2019-12-10-104935_fill_timelines/up.sql @@ -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 [%]'; diff --git a/migrations/sqlite/2019-04-28-201506_create_tantivy_index/down.sql b/migrations/sqlite/2019-04-28-201506_create_tantivy_index/down.sql deleted file mode 100644 index 41b20eb3..00000000 --- a/migrations/sqlite/2019-04-28-201506_create_tantivy_index/down.sql +++ /dev/null @@ -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) ---#!} diff --git a/migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql b/migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql deleted file mode 100644 index 9d331b4e..00000000 --- a/migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql +++ /dev/null @@ -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(()) ---#!} diff --git a/migrations/sqlite/2019-06-24-105533_use_timelines_for_feed/up.sql b/migrations/sqlite/2019-06-24-105533_use_timelines_for_feed/up.sql index 96ece8c8..7357b422 100644 --- a/migrations/sqlite/2019-06-24-105533_use_timelines_for_feed/up.sql +++ b/migrations/sqlite/2019-06-24-105533_use_timelines_for_feed/up.sql @@ -1,17 +1,6 @@ -- Your SQL goes here ---#!|conn: &Connection, path: &Path| { ---#! super::timeline::Timeline::new_for_instance(conn, "Local feed".into(), "local".into()).expect("Local feed creation error"); ---#! super::timeline::Timeline::new_for_instance(conn, "Federated feed".into(), "all".into()).expect("Federated feed creation error"); ---#! ---#! for i in 0.. { ---#! 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(()) ---#!} +INSERT INTO timeline_definition (name, query) VALUES + ('Local feed', 'local'), + ('Federated feed', 'all'); +INSERT INTO timeline_definition (user_id,name,query) + select id,'Your feed','followed or ['||fqn||']' from users; diff --git a/migrations/sqlite/2019-12-10-104935_fill_timelines/down.sql b/migrations/sqlite/2019-12-10-104935_fill_timelines/down.sql new file mode 100644 index 00000000..a1708a46 --- /dev/null +++ b/migrations/sqlite/2019-12-10-104935_fill_timelines/down.sql @@ -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' + ); diff --git a/migrations/sqlite/2019-12-10-104935_fill_timelines/up.sql b/migrations/sqlite/2019-12-10-104935_fill_timelines/up.sql new file mode 100644 index 00000000..cfe780f0 --- /dev/null +++ b/migrations/sqlite/2019-12-10-104935_fill_timelines/up.sql @@ -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 [%]';