Compare commits
No commits in common. "b2c5dc2917512f6bd67bba0094da7860c3826a91" and "7f3cf3b2b502f9df8f5a9c75c9090ab3d014d8d3" have entirely different histories.
b2c5dc2917
...
7f3cf3b2b5
4 changed files with 3 additions and 18 deletions
|
@ -2,7 +2,6 @@ CREATE TABLE schoolyears (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
untis_id INTEGER NOT NULL UNIQUE,
|
untis_id INTEGER NOT NULL UNIQUE,
|
||||||
name VARCHAR NOT NULL,
|
name VARCHAR NOT NULL,
|
||||||
active BOOLEAN NOT NULL,
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP
|
updated_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
@ -16,7 +15,7 @@ CREATE TABLE tenants (
|
||||||
untis_id INTEGER NOT NULL UNIQUE,
|
untis_id INTEGER NOT NULL UNIQUE,
|
||||||
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
|
schoolyear_id INTEGER NOT NULL REFERENCES schoolyears(id),
|
||||||
name VARCHAR NOT NULL,
|
name VARCHAR NOT NULL,
|
||||||
active BOOLEAN NOT NULL,
|
active BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP
|
updated_at TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,7 +10,6 @@ pub struct Schoolyear {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub untis_id: i32,
|
pub untis_id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub active: bool,
|
|
||||||
pub created_at: NaiveDateTime,
|
pub created_at: NaiveDateTime,
|
||||||
pub updated_at: Option<NaiveDateTime>,
|
pub updated_at: Option<NaiveDateTime>,
|
||||||
}
|
}
|
||||||
|
@ -20,7 +19,6 @@ pub struct Schoolyear {
|
||||||
pub struct NewSchoolyear<'a> {
|
pub struct NewSchoolyear<'a> {
|
||||||
pub untis_id: i32,
|
pub untis_id: i32,
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
pub active: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, Debug)]
|
#[derive(Identifiable, Queryable, Associations, Debug)]
|
||||||
|
|
|
@ -13,7 +13,6 @@ diesel::table! {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
untis_id -> Integer,
|
untis_id -> Integer,
|
||||||
name -> VarChar,
|
name -> VarChar,
|
||||||
active -> Bool,
|
|
||||||
created_at -> Timestamp,
|
created_at -> Timestamp,
|
||||||
updated_at -> Nullable<Timestamp>,
|
updated_at -> Nullable<Timestamp>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,26 +24,15 @@ async fn fetch_schoolyears(client: &untis::Client, db_conn: &mut PgConnection) -
|
||||||
.map(|y| db::models::NewSchoolyear {
|
.map(|y| db::models::NewSchoolyear {
|
||||||
untis_id: y.id,
|
untis_id: y.id,
|
||||||
name: &y.name,
|
name: &y.name,
|
||||||
active: false,
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<db::models::NewSchoolyear>>(),
|
.collect::<Vec<db::models::NewSchoolyear>>(),
|
||||||
)
|
)
|
||||||
.execute(db_conn)?;
|
.execute(db_conn)?;
|
||||||
|
|
||||||
let id = db::schema::schoolyears::table
|
Ok(db::schema::schoolyears::table
|
||||||
.filter(db::schema::schoolyears::untis_id.eq(client.current_schoolyear().await?.id))
|
.filter(db::schema::schoolyears::untis_id.eq(client.current_schoolyear().await?.id))
|
||||||
.select(db::schema::schoolyears::id)
|
.select(db::schema::schoolyears::id)
|
||||||
.first(db_conn)?;
|
.first(db_conn)?)
|
||||||
|
|
||||||
diesel::update(db::schema::schoolyears::table)
|
|
||||||
.set(db::schema::schoolyears::active.eq(false))
|
|
||||||
.execute(db_conn)?;
|
|
||||||
diesel::update(db::schema::schoolyears::table)
|
|
||||||
.filter(db::schema::schoolyears::id.eq(id))
|
|
||||||
.set(db::schema::schoolyears::active.eq(true))
|
|
||||||
.execute(db_conn)?;
|
|
||||||
|
|
||||||
Ok(id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_current_tenant(
|
async fn fetch_current_tenant(
|
||||||
|
|
Loading…
Reference in a new issue