stoptime-rs/src/seed.rs

42 lines
1.5 KiB
Rust

use diesel::prelude::*;
use crate::models::{Customer, NewCustomer};
use crate::DbConn;
pub fn run(conn: DbConn) -> Result<(), &'static str> {
destroy_all!(Customer, *conn).map_err(|_| "Could not destroy all customers")?;
create!(Customer, new_customer("one"), *conn).expect("foo");
create!(Customer, new_customer("two"), *conn).expect("foo");
Ok(())
}
pub fn new_customer(key: &'static str) -> NewCustomer {
match key {
"one" => NewCustomer {
address_city: "Some City".to_string(),
address_postal_code: "123456".to_string(),
address_street: "Somestreet".to_string(),
email: "info@testcompany.tld".to_string(),
financial_contact: "Financial Office".to_string(),
hourly_rate: Some(100.0),
name: "Test Company".to_string(),
phone: "0123456789".to_string(),
short_name: "Test Co.".to_string(),
time_specification: true,
},
"two" => NewCustomer {
address_city: "Other City".to_string(),
address_postal_code: "654321".to_string(),
address_street: "Otherstreet".to_string(),
email: "info@testcompany2.tld".to_string(),
financial_contact: "Financial Office".to_string(),
hourly_rate: None,
name: "Test Company 2".to_string(),
phone: "0987654321".to_string(),
short_name: "Test 2 Co.".to_string(),
time_specification: false,
},
&_ => unimplemented!(),
}
}