| 1 | //! Persisted domain types, defined as Toasty models. Tables are created from |
| 2 | //! these definitions via [`crate::db`]'s `push_schema`. |
| 3 | //! |
| 4 | //! Foreign keys are kept as plain scalar fields (`owner_id`, `user_id`) and |
| 5 | //! queried explicitly, rather than declaring Toasty relations — simpler and a |
| 6 | //! good fit for our small schema. |
| 7 | |
| 8 | /// A registered user account. |
| 9 | #[derive(Debug, toasty::Model)] |
| 10 | pub struct User { |
| 11 | #[key] |
| 12 | #[auto] |
| 13 | pub id: i64, |
| 14 | #[unique] |
| 15 | pub username: String, |
| 16 | pub email: String, |
| 17 | /// Argon2 PHC-format password hash. |
| 18 | pub password_hash: String, |
| 19 | pub is_admin: bool, |
| 20 | /// Unix timestamp (seconds) of account creation. |
| 21 | pub created_at: i64, |
| 22 | } |
| 23 | |
| 24 | /// A hosted repository, owned by a [`User`]. |
| 25 | #[derive(Debug, toasty::Model)] |
| 26 | pub struct Repository { |
| 27 | #[key] |
| 28 | #[auto] |
| 29 | pub id: i64, |
| 30 | #[index] |
| 31 | pub owner_id: i64, |
| 32 | pub name: String, |
| 33 | pub description: String, |
| 34 | pub is_private: bool, |
| 35 | /// Short name of the default branch, e.g. `main`. |
| 36 | pub default_branch: String, |
| 37 | pub created_at: i64, |
| 38 | } |
| 39 | |
| 40 | /// A web login session, keyed by an opaque random token stored in a cookie. |
| 41 | #[derive(Debug, toasty::Model)] |
| 42 | pub struct Session { |
| 43 | #[key] |
| 44 | pub token: String, |
| 45 | #[index] |
| 46 | pub user_id: i64, |
| 47 | pub created_at: i64, |
| 48 | /// Unix timestamp (seconds) after which the session is invalid. |
| 49 | pub expires_at: i64, |
| 50 | } |
| 51 | |
| 52 | /// A registered SSH public key, used to authenticate git-over-SSH connections. |
| 53 | #[derive(Debug, toasty::Model)] |
| 54 | pub struct SshKey { |
| 55 | #[key] |
| 56 | #[auto] |
| 57 | pub id: i64, |
| 58 | #[index] |
| 59 | pub user_id: i64, |
| 60 | pub title: String, |
| 61 | /// Canonical SHA256 fingerprint, e.g. `SHA256:…`. |
| 62 | #[unique] |
| 63 | pub fingerprint: String, |
| 64 | /// Normalized OpenSSH public-key line. |
| 65 | pub content: String, |
| 66 | pub created_at: i64, |
| 67 | } |