Compare commits
2 Commits
de914e41a9
...
25c0756e70
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25c0756e70 | ||
|
|
7a1617e1ee |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -21,3 +21,6 @@ target
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# generated environment variables file
|
||||||
|
.env.generated
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ impl SQLiteContainer {
|
|||||||
impl DBInfo<OptionalContainerConfig> for SQLiteContainer {
|
impl DBInfo<OptionalContainerConfig> for SQLiteContainer {
|
||||||
async fn get_db_container_config_info(&self) -> DBConfigInfoType {
|
async fn get_db_container_config_info(&self) -> DBConfigInfoType {
|
||||||
// sqlite filepath url does not include the "sqlite://" prefix
|
// sqlite filepath url does not include the "sqlite://" prefix
|
||||||
let sqlite_url = format!("{}", self.get_db_absolute_path().to_string_lossy());
|
let sqlite_url = format!("sqlite://{}", self.get_db_absolute_path().to_string_lossy());
|
||||||
// create the file
|
// create the file
|
||||||
std::fs::create_dir_all(&self.config.absolute_dir_path)
|
std::fs::create_dir_all(&self.config.absolute_dir_path)
|
||||||
.expect("Failed to create directories for SQLite database");
|
.expect("Failed to create directories for SQLite database");
|
||||||
|
|||||||
34
justfile
34
justfile
@@ -1,7 +1,39 @@
|
|||||||
|
set dotenv-load := true
|
||||||
|
set dotenv-filename := "./public/database/.env.generated"
|
||||||
|
|
||||||
simulate *args:
|
simulate *args:
|
||||||
cd src/container && \
|
cd apps/container && \
|
||||||
if [ -n "{{args}}" ]; then \
|
if [ -n "{{args}}" ]; then \
|
||||||
cargo run --bin container-simulate -- --db-type={{args}}; \
|
cargo run --bin container-simulate -- --db-type={{args}}; \
|
||||||
else \
|
else \
|
||||||
cargo run --bin container-simulate; \
|
cargo run --bin container-simulate; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Usage: (following SeaORM migration commands)
|
||||||
|
# init: Initialize migration directory
|
||||||
|
# generate: Generate a new migration file
|
||||||
|
# up: Apply all pending migrations
|
||||||
|
# up -n 10: Apply 10 pending migrations
|
||||||
|
# down: Rollback last applied migration
|
||||||
|
# down -n 10: Rollback last 10 applied migrations
|
||||||
|
# status: Check the status of all migrations
|
||||||
|
# fresh: Drop all tables from the database, then reapply all migrations
|
||||||
|
# refresh: Rollback all applied migrations, then reapply all migrations
|
||||||
|
# reset: Rollback all applied migrations
|
||||||
|
migrate *args:
|
||||||
|
cd public/migration && \
|
||||||
|
if [ -n "{{args}}" ]; then \
|
||||||
|
cargo run -- {{args}}; \
|
||||||
|
else \
|
||||||
|
cargo run; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
generate-entity:
|
||||||
|
# load development environment variables
|
||||||
|
# sea-orm-cli will also load .env file by default
|
||||||
|
cd public/migration && \
|
||||||
|
sea-orm-cli generate entity \
|
||||||
|
-o ../database/src/generated/entities \
|
||||||
|
--with-serde both \
|
||||||
|
--date-time-crate chrono
|
||||||
|
|
||||||
|
|||||||
1
public/database/src/generated.rs
Normal file
1
public/database/src/generated.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod entities;
|
||||||
19
public/database/src/generated/entities/config.rs
Normal file
19
public/database/src/generated/entities/config.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
|
||||||
|
#[sea_orm(table_name = "config")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(unique, primary_key, auto_increment = false)]
|
||||||
|
pub key: String,
|
||||||
|
pub value: String,
|
||||||
|
pub created_at: DateTimeUtc,
|
||||||
|
pub updated_at: DateTimeUtc,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
6
public/database/src/generated/entities/mod.rs
Normal file
6
public/database/src/generated/entities/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
pub mod user;
|
||||||
4
public/database/src/generated/entities/prelude.rs
Normal file
4
public/database/src/generated/entities/prelude.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18
|
||||||
|
|
||||||
|
pub use super::config::Entity as Config;
|
||||||
|
pub use super::user::Entity as User;
|
||||||
23
public/database/src/generated/entities/user.rs
Normal file
23
public/database/src/generated/entities/user.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
|
||||||
|
#[sea_orm(table_name = "user")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: Uuid,
|
||||||
|
#[sea_orm(unique)]
|
||||||
|
pub name: String,
|
||||||
|
pub is_admin: bool,
|
||||||
|
pub password_hash: String,
|
||||||
|
pub salt: String,
|
||||||
|
pub created_at: DateTimeUtc,
|
||||||
|
pub updated_at: DateTimeUtc,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
use sea_orm::ConnectOptions;
|
use sea_orm::ConnectOptions;
|
||||||
|
|
||||||
|
pub mod generated;
|
||||||
|
|
||||||
pub async fn get_connection<T: FnOnce(&mut ConnectOptions) -> &mut ConnectOptions>(
|
pub async fn get_connection<T: FnOnce(&mut ConnectOptions) -> &mut ConnectOptions>(
|
||||||
connection_string: &str,
|
connection_string: &str,
|
||||||
option_fn: Option<T>,
|
option_fn: Option<T>,
|
||||||
|
|||||||
@@ -22,7 +22,12 @@ impl MigrationTrait for Migration {
|
|||||||
Table::create()
|
Table::create()
|
||||||
.table(Config::Table)
|
.table(Config::Table)
|
||||||
.if_not_exists()
|
.if_not_exists()
|
||||||
.col(ColumnDef::new(Config::Key).string().not_null().unique_key())
|
.col(
|
||||||
|
ColumnDef::new(Config::Key)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
.col(ColumnDef::new(Config::Value).string().not_null())
|
.col(ColumnDef::new(Config::Value).string().not_null())
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(Config::CreatedAt)
|
ColumnDef::new(Config::CreatedAt)
|
||||||
|
|||||||
Reference in New Issue
Block a user