| 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 CI run for a pushed commit. |
| 41 | /// |
| 42 | /// `status` is one of `queued`, `running`, `success`, `failure` (a step exited |
| 43 | /// non-zero), or `error` (the runner itself failed). `started_at`/`finished_at` |
| 44 | /// are 0 until they occur. |
| 45 | #[derive(Clone, Debug, toasty::Model)] |
| 46 | pub struct CiRun { |
| 47 | #[key] |
| 48 | #[auto] |
| 49 | pub id: i64, |
| 50 | #[index] |
| 51 | pub repo_id: i64, |
| 52 | /// Full commit SHA the run is for. |
| 53 | pub commit: String, |
| 54 | /// Short branch name that was pushed (e.g. `main`). |
| 55 | pub ref_name: String, |
| 56 | pub status: String, |
| 57 | /// Accumulated run log. |
| 58 | pub log: String, |
| 59 | pub created_at: i64, |
| 60 | pub started_at: i64, |
| 61 | pub finished_at: i64, |
| 62 | } |
| 63 | |
| 64 | /// A web login session, keyed by an opaque random token stored in a cookie. |
| 65 | #[derive(Debug, toasty::Model)] |
| 66 | pub struct Session { |
| 67 | #[key] |
| 68 | pub token: String, |
| 69 | #[index] |
| 70 | pub user_id: i64, |
| 71 | pub created_at: i64, |
| 72 | /// Unix timestamp (seconds) after which the session is invalid. |
| 73 | pub expires_at: i64, |
| 74 | } |
| 75 | |
| 76 | /// A registered SSH public key, used to authenticate git-over-SSH connections. |
| 77 | #[derive(Debug, toasty::Model)] |
| 78 | pub struct SshKey { |
| 79 | #[key] |
| 80 | #[auto] |
| 81 | pub id: i64, |
| 82 | #[index] |
| 83 | pub user_id: i64, |
| 84 | pub title: String, |
| 85 | /// Canonical SHA256 fingerprint, e.g. `SHA256:…`. |
| 86 | #[unique] |
| 87 | pub fingerprint: String, |
| 88 | /// Normalized OpenSSH public-key line. |
| 89 | pub content: String, |
| 90 | pub created_at: i64, |
| 91 | } |