My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat/db: init migration

+128 -1
+5 -1
Cargo.toml
··· 1 1 [workspace] 2 - members = ["crates/db", "crates/sakura"] 2 + members = [ 3 + "crates/db", 4 + "crates/db/migration", 5 + "crates/sakura" 6 + ] 3 7 4 8 5 9 [workspace.package]
+22
crates/db/migration/Cargo.toml
··· 1 + [package] 2 + name = "migration" 3 + version = "0.1.0" 4 + edition = "2021" 5 + publish = false 6 + 7 + [lib] 8 + name = "migration" 9 + path = "src/lib.rs" 10 + 11 + [dependencies] 12 + async-std = { version = "1", features = ["attributes", "tokio1"] } 13 + 14 + [dependencies.sea-orm-migration] 15 + version = "1.1.0" 16 + features = [ 17 + # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. 18 + # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime. 19 + # e.g. 20 + # "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature 21 + # "sqlx-postgres", # `DATABASE_DRIVER` feature 22 + ]
+41
crates/db/migration/README.md
··· 1 + # Running Migrator CLI 2 + 3 + - Generate a new migration file 4 + ```sh 5 + cargo run -- generate MIGRATION_NAME 6 + ``` 7 + - Apply all pending migrations 8 + ```sh 9 + cargo run 10 + ``` 11 + ```sh 12 + cargo run -- up 13 + ``` 14 + - Apply first 10 pending migrations 15 + ```sh 16 + cargo run -- up -n 10 17 + ``` 18 + - Rollback last applied migrations 19 + ```sh 20 + cargo run -- down 21 + ``` 22 + - Rollback last 10 applied migrations 23 + ```sh 24 + cargo run -- down -n 10 25 + ``` 26 + - Drop all tables from the database, then reapply all migrations 27 + ```sh 28 + cargo run -- fresh 29 + ``` 30 + - Rollback all applied migrations, then reapply all migrations 31 + ```sh 32 + cargo run -- refresh 33 + ``` 34 + - Rollback all applied migrations 35 + ```sh 36 + cargo run -- reset 37 + ``` 38 + - Check the status of all migrations 39 + ```sh 40 + cargo run -- status 41 + ```
+12
crates/db/migration/src/lib.rs
··· 1 + pub use sea_orm_migration::prelude::*; 2 + 3 + mod m20220101_000001_create_table; 4 + 5 + pub struct Migrator; 6 + 7 + #[async_trait::async_trait] 8 + impl MigratorTrait for Migrator { 9 + fn migrations() -> Vec<Box<dyn MigrationTrait>> { 10 + vec![Box::new(m20220101_000001_create_table::Migration)] 11 + } 12 + }
+41
crates/db/migration/src/m20220101_000001_create_table.rs
··· 1 + use sea_orm_migration::{prelude::*, schema::*}; 2 + 3 + #[derive(DeriveMigrationName)] 4 + pub struct Migration; 5 + 6 + #[async_trait::async_trait] 7 + impl MigrationTrait for Migration { 8 + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { 9 + // Replace the sample below with your own migration scripts 10 + todo!(); 11 + 12 + manager 13 + .create_table( 14 + Table::create() 15 + .table(Post::Table) 16 + .if_not_exists() 17 + .col(pk_auto(Post::Id)) 18 + .col(string(Post::Title)) 19 + .col(string(Post::Text)) 20 + .to_owned(), 21 + ) 22 + .await 23 + } 24 + 25 + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { 26 + // Replace the sample below with your own migration scripts 27 + todo!(); 28 + 29 + manager 30 + .drop_table(Table::drop().table(Post::Table).to_owned()) 31 + .await 32 + } 33 + } 34 + 35 + #[derive(DeriveIden)] 36 + enum Post { 37 + Table, 38 + Id, 39 + Title, 40 + Text, 41 + }
+6
crates/db/migration/src/main.rs
··· 1 + use sea_orm_migration::prelude::*; 2 + 3 + #[async_std::main] 4 + async fn main() { 5 + cli::run_cli(migration::Migrator).await; 6 + }
+1
flake.nix
··· 72 72 cargo-edit 73 73 cargo-watch 74 74 rust-analyzer 75 + sea-orm-cli 75 76 76 77 bacon 77 78 ];