mirror of
https://github.com/goauthentik/authentik
synced 2026-04-26 01:25:02 +02:00
42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
use std::{
|
|
fs::read_to_string,
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
use eyre::Result;
|
|
|
|
pub(crate) fn read_migrate_file(file: &Path) -> Result<Vec<(PathBuf, PathBuf)>> {
|
|
let contents = read_to_string(file)?;
|
|
let lines: Vec<String> = contents
|
|
.split('\n')
|
|
.map(|x| x.to_owned())
|
|
.filter(|x| !x.is_empty())
|
|
.collect();
|
|
let migrations = lines
|
|
.iter()
|
|
.filter_map(|x| x.split_once(" -> "))
|
|
.filter(|x| x.0 != x.1)
|
|
.map(|x| {
|
|
(
|
|
x.0.parse().expect("a valid path"),
|
|
x.1.parse().expect("a valid path"),
|
|
)
|
|
})
|
|
.collect::<Vec<_>>();
|
|
Ok(migrations)
|
|
}
|
|
|
|
pub(crate) fn read_migrate_file_left_side(file: &Path) -> Result<Vec<PathBuf>> {
|
|
let contents = read_to_string(file)?;
|
|
let lines: Vec<String> = contents
|
|
.split('\n')
|
|
.map(|x| x.to_owned())
|
|
.filter(|x| !x.is_empty())
|
|
.collect();
|
|
let migrations = lines
|
|
.iter()
|
|
.map(|x| x.split(" -> ").next().unwrap().into())
|
|
.collect::<Vec<_>>();
|
|
Ok(migrations)
|
|
}
|