-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub async fn exec(rb: &rbatis::RBatis) -> Result<(), Box<dyn std::error::Error>> { | ||
let sql = std::fs::read_to_string("./table_pg.sql")?; | ||
rb.exec(&sql, vec![]).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
pub async fn exec(rb: &rbatis::RBatis) -> Result<(), Box<dyn std::error::Error>> { | ||
let is_content_migrated: bool = rb | ||
.query_decode::<u64>( | ||
"select count(1) as count from migration where key='content_migration'", | ||
vec![], | ||
) | ||
.await? | ||
> 0; | ||
|
||
if !is_content_migrated { | ||
let posts: Vec<blog_server_services::traits::post_service::Post> = | ||
rb.query_decode("select * from post", vec![]).await?; | ||
for post in posts { | ||
let content = post | ||
.base | ||
.content | ||
.as_ref() | ||
.map(|c| blog_server_services::utils::html::clean(c)); | ||
let plain_text_content = content | ||
.as_ref() | ||
.map(|c| blog_server_services::utils::html::to_plain(c)); | ||
rb.query( | ||
"update post set content=?, plain_text_content=? where id=?", | ||
vec![ | ||
rbs::to_value!(content), | ||
rbs::to_value!(plain_text_content), | ||
rbs::to_value!(post.id), | ||
], | ||
) | ||
.await?; | ||
} | ||
rb.query( | ||
"insert into migration (key) values ('content_migration')", | ||
vec![], | ||
) | ||
.await?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod base; | ||
mod content; | ||
|
||
pub async fn exec(rb: &rbatis::RBatis) -> Result<(), Box<dyn std::error::Error>> { | ||
base::exec(rb).await?; | ||
content::exec(rb).await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters