bin: add migration of finished fs tasks
This commit is contained in:
parent
73ab922c77
commit
8bd588070e
6 changed files with 58 additions and 19 deletions
|
@ -4,9 +4,12 @@ use xdg::BaseDirectories;
|
|||
fn main() {
|
||||
let xdg_dirs = BaseDirectories::with_prefix(env!("CARGO_PKG_NAME")).unwrap();
|
||||
let fs_repo = repo::fs::FsRepo::new(xdg_dirs.clone());
|
||||
let fs_tasks = fs_repo.get_tasks(false).unwrap();
|
||||
let sqlite_repo = repo::sqlite::SqliteRepo::new(xdg_dirs.clone()).unwrap();
|
||||
|
||||
let sqlite_repo = repo::sqlite::SqliteRepo::new(xdg_dirs).unwrap();
|
||||
log::info!("active tasks");
|
||||
|
||||
let fs_tasks = fs_repo.get_tasks(false).unwrap();
|
||||
if !fs_tasks.is_empty() {
|
||||
for task in fs_tasks {
|
||||
log::info!("task: {}", task.name);
|
||||
log::info!(" inserting...");
|
||||
|
@ -18,9 +21,41 @@ fn main() {
|
|||
link: task.link,
|
||||
dir_path: task.dir_path,
|
||||
index: None,
|
||||
finished_at: None,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
log::info!(" inserted");
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("finished tasks");
|
||||
|
||||
let fs_tasks = fs_repo.get_tasks(true).unwrap();
|
||||
if !fs_tasks.is_empty() {
|
||||
let meta = std::fs::metadata(xdg_dirs.get_data_file(repo::fs::FINISHED_DATA_FILE)).unwrap();
|
||||
let finished_at = meta
|
||||
.modified()
|
||||
.map(time::OffsetDateTime::from)
|
||||
.unwrap_or_else(|_| time::OffsetDateTime::now_utc());
|
||||
|
||||
for task in fs_tasks {
|
||||
log::info!("task: {}", task.name);
|
||||
log::info!(" inserting...");
|
||||
|
||||
sqlite_repo
|
||||
.insert_task(repo::InsertTaskData {
|
||||
name: task.name,
|
||||
project: task.project,
|
||||
link: task.link,
|
||||
dir_path: task.dir_path,
|
||||
index: None,
|
||||
finished_at: Some(finished_at),
|
||||
})
|
||||
// TODO: think of a better solution than idx
|
||||
.ok();
|
||||
|
||||
log::info!(" inserted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ pub fn execute(repo: impl Repository, args: Args) {
|
|||
.transpose()
|
||||
.unwrap(),
|
||||
index: None,
|
||||
finished_at: None,
|
||||
});
|
||||
|
||||
match res {
|
||||
|
|
|
@ -77,6 +77,7 @@ pub fn execute(repo: impl Repository, args: Args) {
|
|||
project: target.project,
|
||||
link: target.link,
|
||||
dir_path: target.dir_path,
|
||||
finished_at: None,
|
||||
});
|
||||
match res {
|
||||
Ok(task) => {
|
||||
|
|
|
@ -55,6 +55,7 @@ pub struct InsertTaskData {
|
|||
pub link: Option<String>,
|
||||
pub dir_path: Option<PathBuf>,
|
||||
pub index: Option<usize>,
|
||||
pub finished_at: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
pub struct UpdateTaskData {
|
||||
|
|
|
@ -60,9 +60,9 @@ impl From<CurrentTaskInfo> for domain::CurrentTaskInfo {
|
|||
}
|
||||
}
|
||||
|
||||
const CURRENT_TASK_FILE: &str = "current.json";
|
||||
const DATA_FILE: &str = "data.json";
|
||||
const FINISHED_DATA_FILE: &str = "finished_data.json";
|
||||
pub const CURRENT_TASK_FILE: &str = "current.json";
|
||||
pub const DATA_FILE: &str = "data.json";
|
||||
pub const FINISHED_DATA_FILE: &str = "finished_data.json";
|
||||
|
||||
pub struct FsRepo {
|
||||
xdg_dirs: BaseDirectories,
|
||||
|
|
|
@ -121,8 +121,8 @@ impl Repository for SqliteRepo {
|
|||
let mut stmt = self
|
||||
.conn
|
||||
.prepare(
|
||||
"INSERT INTO tasks (name, project, link, dir_path)
|
||||
VALUES (?1, ?2, ?3, ?4)",
|
||||
"INSERT INTO tasks (name, project, link, dir_path, created_at, finished_at)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?5)",
|
||||
)
|
||||
.map_err(|_| Error::PrepareQuery)?;
|
||||
|
||||
|
@ -134,6 +134,7 @@ impl Repository for SqliteRepo {
|
|||
&insert_data
|
||||
.dir_path
|
||||
.and_then(|p| p.into_os_string().into_string().ok()),
|
||||
&insert_data.finished_at,
|
||||
))
|
||||
.map_err(|_| Error::InsertData)?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue