From 2f356f38c3882509f8f59bdee2f5c66b98b5b375 Mon Sep 17 00:00:00 2001 From: caipira113 Date: Sun, 29 Oct 2023 15:51:39 +0900 Subject: [PATCH] Misskey 2023.11.0-beta.4 compatible (only aid) https://github.com/misskey-dev/misskey/commit/1fa1d316969de15d6aaef1dbf0a0b95aec30e377 F-word. --- README.md | 5 ++++ config-example.json | 1 + src/config.rs | 1 + src/database.rs | 57 +++++++++++++++++++++++++++++++++------------ src/main.rs | 1 + 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index da8a44c..6507edd 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ This tool is designed to migrate data from PostgreSQL to Meilisearch and is inte ![Screenshot](assets/Screenshot_2.png) +## Warning +If you have Misskey 2023.11.0-beta.4 or earlier, please set the `idtype` in your configuration to `null`. + +**Currently, we only support AID.** + ## Docker Image ```docker asia-docker.pkg.dev/libnare/mk-meili-mgn/main:latest diff --git a/config-example.json b/config-example.json index 37a05e2..5f26baa 100644 --- a/config-example.json +++ b/config-example.json @@ -15,6 +15,7 @@ "index": "undefined" }, "option": { + "idtype": "aid", "localonly": false, "limit": null } diff --git a/src/config.rs b/src/config.rs index cf0951b..e279244 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,6 +32,7 @@ pub struct MeiliConfig { #[derive(Debug, Deserialize)] pub struct OptionConfig { + pub idtype: Option, pub localonly: bool, pub limit: Option, } diff --git a/src/database.rs b/src/database.rs index 2bf25f6..4d7e0d8 100644 --- a/src/database.rs +++ b/src/database.rs @@ -5,6 +5,7 @@ use tokio_postgres::{Client, NoTls}; use crate::config::config; use crate::r#struct::Notes; +use crate::aid; pub async fn connect_db() -> Result> { let config = config()?; @@ -33,7 +34,13 @@ pub async fn query_notes(db: &Client) -> Result, Box> { let config = config()?; let mut query = std::string::String::from(" - SELECT id, \"createdAt\", \"userId\", \"userHost\", \"channelId\", cw, text, tags + SELECT id, "); + + if config.option.idtype.is_none() { + query.push_str("\"createdAt\", "); + } + + query.push_str("\"userId\", \"userHost\", \"channelId\", cw, text, tags FROM note WHERE COALESCE(text, cw) IS NOT NULL AND visibility IN ('home', 'public') @@ -51,20 +58,40 @@ pub async fn query_notes(db: &Client) -> Result, Box> { let mut data_vec = Vec::new(); - for row in rows { - let created_at: DateTime = row.get("createdAt"); - let notes = Notes { - id: row.get("id"), - created_at: created_at.timestamp() * 1000 + created_at.timestamp_subsec_millis() as i64, - user_id: row.get("userId"), - user_host: row.get("userHost"), - channel_id: row.get("channelId"), - cw: row.get("cw"), - text: row.get("text"), - tags: row.get("tags"), - }; - - data_vec.push(notes); + if config.option.idtype.is_none() { + for row in rows { + let created_at: DateTime = row.get("createdAt"); + let notes = Notes { + id: row.get("id"), + created_at: created_at.timestamp() * 1000 + created_at.timestamp_subsec_millis() as i64, + user_id: row.get("userId"), + user_host: row.get("userHost"), + channel_id: row.get("channelId"), + cw: row.get("cw"), + text: row.get("text"), + tags: row.get("tags"), + }; + + data_vec.push(notes); + } + } else if config.option.idtype.as_ref().unwrap() == "aid" { + for row in rows { + let created_at: DateTime = aid::parse(row.get("id")); + let notes = Notes { + id: row.get("id"), + created_at: created_at.timestamp() * 1000 + created_at.timestamp_subsec_millis() as i64, + user_id: row.get("userId"), + user_host: row.get("userHost"), + channel_id: row.get("channelId"), + cw: row.get("cw"), + text: row.get("text"), + tags: row.get("tags"), + }; + + data_vec.push(notes); + } + } else { + panic!("Invalid idtype: {}", config.option.idtype.as_ref().unwrap()); } Ok(data_vec) diff --git a/src/main.rs b/src/main.rs index f41cf04..f54b61f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ mod database; mod config; mod r#struct; mod meili; +mod aid; #[tokio::main] async fn main() -> Result<(), Box> {