Skip to content

Commit

Permalink
add iko
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Apr 30, 2022
1 parent 380f368 commit 04202dd
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions iko/.gitignore
@@ -0,0 +1 @@
/target/
7 changes: 7 additions & 0 deletions iko/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions iko/Cargo.toml
@@ -0,0 +1,8 @@
[package]
name = "iko"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
1 change: 1 addition & 0 deletions iko/README.md
@@ -0,0 +1 @@
# iko
47 changes: 47 additions & 0 deletions iko/src/lib.rs
@@ -0,0 +1,47 @@
#[cfg(test)]
mod tests {
#[test]
fn test() {
trait Migration {
fn migrate(&self);
fn version(&self) -> u32;
}

struct Migration1 {}
impl Migration for Migration1 {
fn migrate(&self) {
println!("migrate1");
}

fn version(&self) -> u32 {
1
}
}

struct Migration2 {}
impl Migration for Migration2 {
fn migrate(&self) {
println!("migrate2");
}

fn version(&self) -> u32 {
2
}
}

let mut current_version = 0;
let migrations: Vec<Box<dyn Migration>> =
vec![Box::new(Migration1 {}), Box::new(Migration2 {})];
for migration in migrations {
// load_and_lock_current_version()
if current_version + 1 != migration.version() {
continue;
}

migration.migrate();

// save_and_unlock_current_version()
current_version += 1;
}
}
}

0 comments on commit 04202dd

Please sign in to comment.