starting point to specify what we're doing
This commit is contained in:
commit
9676f7d7e1
15 changed files with 5837 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
migration/target
|
4013
Cargo.lock
generated
Normal file
4013
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "bus_api"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.79"
|
||||
reqwest = "0.11.24"
|
||||
sea-orm = "0.12.14"
|
||||
serde = { version = "1.0.196", features = ["derive"] }
|
||||
serde_json = "1.0.113"
|
||||
tide = "0.16.0"
|
||||
tokio = { version = "1.36.0", features = ["full"] }
|
1681
migration/Cargo.lock
generated
Normal file
1681
migration/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
22
migration/Cargo.toml
Normal file
22
migration/Cargo.toml
Normal file
|
@ -0,0 +1,22 @@
|
|||
[package]
|
||||
name = "migration"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "migration"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
async-std = { version = "1", features = ["attributes", "tokio1"] }
|
||||
|
||||
[dependencies.sea-orm-migration]
|
||||
version = "0.12.0"
|
||||
features = [
|
||||
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
|
||||
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
|
||||
# e.g.
|
||||
# "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
||||
# "sqlx-postgres", # `DATABASE_DRIVER` feature
|
||||
]
|
41
migration/README.md
Normal file
41
migration/README.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
# Running Migrator CLI
|
||||
|
||||
- Generate a new migration file
|
||||
```sh
|
||||
cargo run -- generate MIGRATION_NAME
|
||||
```
|
||||
- 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
|
||||
```
|
12
migration/src/lib.rs
Normal file
12
migration/src/lib.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20220101_000001_create_table;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20220101_000001_create_table::Migration)]
|
||||
}
|
||||
}
|
0
migration/src/m20240217_000000_create_a
Normal file
0
migration/src/m20240217_000000_create_a
Normal file
0
migration/src/m20240217_000000_create_b
Normal file
0
migration/src/m20240217_000000_create_b
Normal file
0
migration/src/m20240217_000000_create_bus_table.rs
Normal file
0
migration/src/m20240217_000000_create_bus_table.rs
Normal file
0
migration/src/m20240217_000000_create_route_table.rs
Normal file
0
migration/src/m20240217_000000_create_route_table.rs
Normal file
0
migration/src/m20240217_000000_create_stop_table.rs
Normal file
0
migration/src/m20240217_000000_create_stop_table.rs
Normal file
6
migration/src/main.rs
Normal file
6
migration/src/main.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
cli::run_cli(migration::Migrator).await;
|
||||
}
|
32
src/main.rs
Normal file
32
src/main.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
extern crate tokio;
|
||||
extern crate reqwest;
|
||||
extern crate tide;
|
||||
extern crate anyhow;
|
||||
extern crate sea_orm;
|
||||
|
||||
mod state;
|
||||
|
||||
use tide::prelude::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let mut app = tide::with_state(state::State::new().await?);
|
||||
|
||||
app.at("/path").get(transit_path);
|
||||
app.at("/time-to-arrive").get(transit_estimate);
|
||||
|
||||
// TODO: change to 0.0.0.0 when docker image done
|
||||
app.listen("127.0.0.1:8080").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
/// return the best path with the request specifying ISO time, lat and longitude in query params
|
||||
async fn transit_path(mut req: tide::Request<state::State>)->tide::Result{
|
||||
Ok("".into())
|
||||
}
|
||||
|
||||
/// return the num of estimated seconds for bus id and stop ids given in query params
|
||||
async fn transit_estimate(mut req: tide::Request<state::State>)->tide::Result{
|
||||
Ok("".into())
|
||||
}
|
13
src/state.rs
Normal file
13
src/state.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
#[derive(Clone)]
|
||||
pub struct State{
|
||||
pub db: sea_orm::DatabaseConnection
|
||||
}
|
||||
|
||||
const DEFAULT_DB_CONN:&'static str = "sqlite://default_db.db";
|
||||
impl State{
|
||||
pub async fn new() -> anyhow::Result<Self> {
|
||||
Ok(Self{
|
||||
db: sea_orm::Database::connect(DEFAULT_DB_CONN).await?
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue