Skip to content

Commit 7e9eace

Browse files
author
Josh Leeb-du Toit
committed
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 41442f0 commit 7e9eace

File tree

6 files changed

+90
-1
lines changed

6 files changed

+90
-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/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/models/mod.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/schema.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ index df884e4..18e08cd 100644
6666
joinable!(version_authors -> users (user_id));
6767
joinable!(version_authors -> versions (version_id));
6868
joinable!(version_downloads -> versions (version_id));
69-
joinable!(versions -> crates (crate_id));
69+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
7070

7171
@@ -913,12 +935,13 @@ allow_tables_to_appear_in_same_query!(
7272
dependencies,

src/schema.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,54 @@ table! {
834834
}
835835
}
836836

837+
table! {
838+
use diesel::sql_types::*;
839+
use diesel_full_text_search::{TsVector as Tsvector};
840+
use diesel_ltree::Ltree;
841+
842+
/// Representation of the `version_owner_actions` table.
843+
///
844+
/// (Automatically generated by Diesel.)
845+
version_owner_actions (id) {
846+
/// The `id` column of the `version_owner_actions` table.
847+
///
848+
/// Its SQL type is `Int4`.
849+
///
850+
/// (Automatically generated by Diesel.)
851+
id -> Int4,
852+
/// The `version_id` column of the `version_owner_actions` table.
853+
///
854+
/// Its SQL type is `Nullable<Int4>`.
855+
///
856+
/// (Automatically generated by Diesel.)
857+
version_id -> Nullable<Int4>,
858+
/// The `owner_id` column of the `version_owner_actions` table.
859+
///
860+
/// Its SQL type is `Nullable<Int4>`.
861+
///
862+
/// (Automatically generated by Diesel.)
863+
owner_id -> Nullable<Int4>,
864+
/// The `owner_token_id` column of the `version_owner_actions` table.
865+
///
866+
/// Its SQL type is `Nullable<Int4>`.
867+
///
868+
/// (Automatically generated by Diesel.)
869+
owner_token_id -> Nullable<Int4>,
870+
/// The `action` column of the `version_owner_actions` table.
871+
///
872+
/// Its SQL type is `Int4`.
873+
///
874+
/// (Automatically generated by Diesel.)
875+
action -> Int4,
876+
/// The `time` column of the `version_owner_actions` table.
877+
///
878+
/// Its SQL type is `Timestamp`.
879+
///
880+
/// (Automatically generated by Diesel.)
881+
time -> Timestamp,
882+
}
883+
}
884+
837885
table! {
838886
use diesel::sql_types::*;
839887
use diesel_full_text_search::{TsVector as Tsvector};
@@ -926,6 +974,9 @@ joinable!(recent_crate_downloads -> crates (crate_id));
926974
joinable!(version_authors -> users (user_id));
927975
joinable!(version_authors -> versions (version_id));
928976
joinable!(version_downloads -> versions (version_id));
977+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
978+
joinable!(version_owner_actions -> users (owner_id));
979+
joinable!(version_owner_actions -> versions (version_id));
929980
joinable!(versions -> crates (crate_id));
930981

931982
allow_tables_to_appear_in_same_query!(
@@ -950,5 +1001,6 @@ allow_tables_to_appear_in_same_query!(
9501001
users,
9511002
version_authors,
9521003
version_downloads,
1004+
version_owner_actions,
9531005
versions,
9541006
);

0 commit comments

Comments
 (0)