spit into crates and fix app
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
9
neo-migration/Cargo.toml
Normal file
9
neo-migration/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "neo-migration"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
sea-orm-migration = "^0.8"
|
||||
neo-entity = { path = "../neo-entity" }
|
37
neo-migration/README.md
Normal file
37
neo-migration/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Running Migrator CLI
|
||||
|
||||
- Apply all pending migrations
|
||||
```sh
|
||||
cargo run
|
||||
```
|
||||
```sh
|
||||
cargo run -- up
|
||||
```
|
||||
- Apply first 10 pending migrations
|
||||
```sh
|
||||
cargo run -- up -n 10
|
||||
```
|
||||
- Rollback last applied migrations
|
||||
```sh
|
||||
cargo run -- down
|
||||
```
|
||||
- Rollback last 10 applied migrations
|
||||
```sh
|
||||
cargo run -- down -n 10
|
||||
```
|
||||
- Drop all tables from the database, then reapply all migrations
|
||||
```sh
|
||||
cargo run -- fresh
|
||||
```
|
||||
- Rollback all applied migrations, then reapply all migrations
|
||||
```sh
|
||||
cargo run -- refresh
|
||||
```
|
||||
- Rollback all applied migrations
|
||||
```sh
|
||||
cargo run -- reset
|
||||
```
|
||||
- Check the status of all migrations
|
||||
```sh
|
||||
cargo run -- status
|
||||
```
|
18
neo-migration/src/lib.rs
Normal file
18
neo-migration/src/lib.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20220707_092851_create_users;
|
||||
mod m20220707_112339_create_devices;
|
||||
mod m20220707_143304_create_sessions;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20220707_092851_create_users::Migration),
|
||||
Box::new(m20220707_112339_create_devices::Migration),
|
||||
Box::new(m20220707_143304_create_sessions::Migration),
|
||||
]
|
||||
}
|
||||
}
|
49
neo-migration/src/m20220707_092851_create_users.rs
Normal file
49
neo-migration/src/m20220707_092851_create_users.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use neo_entity::users::{self, Entity as User};
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20220707_092851_create_users"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(User)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(users::Column::Uuid)
|
||||
.uuid()
|
||||
.primary_key()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(users::Column::UserId).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(users::Column::DisplayName)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(users::Column::PasswordHash)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.table(User)
|
||||
.col(users::Column::UserId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
57
neo-migration/src/m20220707_112339_create_devices.rs
Normal file
57
neo-migration/src/m20220707_112339_create_devices.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use neo_entity::devices::{self, Entity as Device};
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20220707_112339_create_devices.rs"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Device)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(devices::Column::Uuid)
|
||||
.uuid()
|
||||
.primary_key()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(devices::Column::UserUuid).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(devices::Column::DeviceId)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(devices::Column::DisplayName)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.table(Device)
|
||||
.col(devices::Column::DeviceId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.table(Device)
|
||||
.col(devices::Column::UserUuid)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
44
neo-migration/src/m20220707_143304_create_sessions.rs
Normal file
44
neo-migration/src/m20220707_143304_create_sessions.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use neo_entity::sessions::{self, Entity as Session};
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20220707_143304_create_sessions.rs"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Session)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(sessions::Column::Uuid)
|
||||
.uuid()
|
||||
.primary_key()
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(sessions::Column::DeviceUuid)
|
||||
.uuid()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(sessions::Column::Key).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.table(Session)
|
||||
.col(sessions::Column::DeviceUuid)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user