Skip to content

Commit 5accf6a

Browse files
Josh Leeb-du Toitmarkcatley
authored andcommitted
Add migration and model for version_owner_actions table
Add a migration to create the `version_owner_actions` table, as well as a `VersionOwnerAction` struct in `models/actions.rs`.
1 parent f41626e commit 5accf6a

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE version_owner_actions;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE version_owner_actions (
2+
id SERIAL PRIMARY KEY,
3+
version_id INTEGER REFERENCES versions(id) ON DELETE CASCADE,
4+
owner_id INTEGER REFERENCES users(id),
5+
owner_token_id INTEGER REFERENCES api_tokens(id),
6+
action INTEGER NOT NULL,
7+
time TIMESTAMP NOT NULL DEFAULT now()
8+
);

src/models.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub use self::action::{VersionAction, VersionOwnerAction};
12
pub use self::badge::{Badge, CrateBadge, MaintenanceStatus};
23
pub use self::category::{Category, CrateCategory, NewCategory};
34
pub use self::crate_owner_invitation::{CrateOwnerInvitation, NewCrateOwnerInvitation};
@@ -16,6 +17,7 @@ pub use self::version::{NewVersion, Version};
1617

1718
pub mod helpers;
1819

20+
mod action;
1921
mod badge;
2022
pub mod category;
2123
mod crate_owner_invitation;

src/models/action.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use chrono::NaiveDateTime;
2+
3+
use crate::models::{ApiToken, User, Version};
4+
use crate::schema::*;
5+
6+
#[derive(Debug, Clone, Copy)]
7+
#[repr(u32)]
8+
pub enum VersionAction {
9+
Publish = 0,
10+
Yank = 1,
11+
Unyank = 2,
12+
}
13+
14+
#[derive(Debug, Clone, Copy, Queryable, Identifiable, Associations)]
15+
#[belongs_to(Version)]
16+
#[belongs_to(User, foreign_key = "owner_id")]
17+
#[belongs_to(ApiToken, foreign_key = "owner_token_id")]
18+
#[table_name = "version_owner_actions"]
19+
pub struct VersionOwnerAction {
20+
pub id: i32,
21+
pub version_id: i32,
22+
pub owner_id: i32,
23+
pub owner_token_id: i32,
24+
pub action: VersionAction,
25+
pub time: NaiveDateTime,
26+
}

src/schema.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ index df884e4..18e08cd 100644
7979
joinable!(version_authors -> users (user_id));
8080
joinable!(version_authors -> versions (version_id));
8181
joinable!(version_downloads -> versions (version_id));
82-
joinable!(versions -> crates (crate_id));
82+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
8383

8484
@@ -913,12 +935,13 @@ allow_tables_to_appear_in_same_query!(
8585
dependencies,

src/schema.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,53 @@ table! {
855855
}
856856
}
857857

858+
table! {
859+
use diesel::sql_types::*;
860+
use diesel_full_text_search::{TsVector as Tsvector};
861+
862+
/// Representation of the `version_owner_actions` table.
863+
///
864+
/// (Automatically generated by Diesel.)
865+
version_owner_actions (id) {
866+
/// The `id` column of the `version_owner_actions` table.
867+
///
868+
/// Its SQL type is `Int4`.
869+
///
870+
/// (Automatically generated by Diesel.)
871+
id -> Int4,
872+
/// The `version_id` column of the `version_owner_actions` table.
873+
///
874+
/// Its SQL type is `Nullable<Int4>`.
875+
///
876+
/// (Automatically generated by Diesel.)
877+
version_id -> Nullable<Int4>,
878+
/// The `owner_id` column of the `version_owner_actions` table.
879+
///
880+
/// Its SQL type is `Nullable<Int4>`.
881+
///
882+
/// (Automatically generated by Diesel.)
883+
owner_id -> Nullable<Int4>,
884+
/// The `owner_token_id` column of the `version_owner_actions` table.
885+
///
886+
/// Its SQL type is `Nullable<Int4>`.
887+
///
888+
/// (Automatically generated by Diesel.)
889+
owner_token_id -> Nullable<Int4>,
890+
/// The `action` column of the `version_owner_actions` table.
891+
///
892+
/// Its SQL type is `Int4`.
893+
///
894+
/// (Automatically generated by Diesel.)
895+
action -> Int4,
896+
/// The `time` column of the `version_owner_actions` table.
897+
///
898+
/// Its SQL type is `Timestamp`.
899+
///
900+
/// (Automatically generated by Diesel.)
901+
time -> Timestamp,
902+
}
903+
}
904+
858905
table! {
859906
use diesel::sql_types::*;
860907
use diesel_full_text_search::{TsVector as Tsvector};
@@ -975,6 +1022,9 @@ joinable!(recent_crate_downloads -> crates (crate_id));
9751022
joinable!(version_authors -> users (user_id));
9761023
joinable!(version_authors -> versions (version_id));
9771024
joinable!(version_downloads -> versions (version_id));
1025+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
1026+
joinable!(version_owner_actions -> users (owner_id));
1027+
joinable!(version_owner_actions -> versions (version_id));
9781028
joinable!(versions -> crates (crate_id));
9791029
joinable!(versions -> users (published_by));
9801030
joinable!(versions_published_by -> versions (version_id));
@@ -1002,6 +1052,7 @@ allow_tables_to_appear_in_same_query!(
10021052
users,
10031053
version_authors,
10041054
version_downloads,
1055+
version_owner_actions,
10051056
versions,
10061057
versions_published_by,
10071058
);

0 commit comments

Comments
 (0)