Skip to content

Commit

Permalink
AID Series
Browse files Browse the repository at this point in the history
  • Loading branch information
caipira113 committed Oct 29, 2023
1 parent c4a0b87 commit 81aa452
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This tool is designed to migrate data from PostgreSQL to Meilisearch and is inte
## 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.**
**Currently, we only support AID and AIDX.**

## Docker Image
```docker
Expand Down
File renamed without changes.
38 changes: 20 additions & 18 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tokio_postgres::{Client, NoTls};

use crate::config::config;
use crate::r#struct::Notes;
use crate::aid;
use crate::aid_series;

pub async fn connect_db() -> Result<Client, Box<dyn Error>> {
let config = config()?;
Expand Down Expand Up @@ -74,24 +74,26 @@ pub async fn query_notes(db: &Client) -> Result<Vec<Notes>, Box<dyn Error>> {

data_vec.push(notes);
}
} else if config.option.idtype.as_ref().unwrap() == "aid" {
for row in rows {
let created_at: DateTime<Utc> = 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 if let Some(idtype) = config.option.idtype.as_ref() {
if idtype == "aid" || idtype == "aidx" {
for row in rows {
let created_at: DateTime<Utc> = aid_series::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: {}", idtype);
}
} else {
panic!("Invalid idtype: {}", config.option.idtype.as_ref().unwrap());
}

Ok(data_vec)
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod database;
mod config;
mod r#struct;
mod meili;
mod aid;
mod aid_series;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand Down

0 comments on commit 81aa452

Please sign in to comment.