Skip to content

Commit ccfda71

Browse files
committed
Auto merge of #1604 - joshleeb:version-owner-actions, r=carols10cents
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`. Ref. #1548 (Task 2)
2 parents db7f5ca + e5c6242 commit ccfda71

File tree

7 files changed

+97
-1
lines changed

7 files changed

+97
-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
@@ -80,7 +80,7 @@ index df884e4..18e08cd 100644
8080
joinable!(version_authors -> users (user_id));
8181
joinable!(version_authors -> versions (version_id));
8282
joinable!(version_downloads -> versions (version_id));
83-
joinable!(versions -> crates (crate_id));
83+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
8484

8585
@@ -913,13 +935,14 @@ allow_tables_to_appear_in_same_query!(
8686
emails,

src/schema.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,53 @@ table! {
860860
}
861861
}
862862

863+
table! {
864+
use diesel::sql_types::*;
865+
use diesel_full_text_search::{TsVector as Tsvector};
866+
867+
/// Representation of the `version_owner_actions` table.
868+
///
869+
/// (Automatically generated by Diesel.)
870+
version_owner_actions (id) {
871+
/// The `id` column of the `version_owner_actions` table.
872+
///
873+
/// Its SQL type is `Int4`.
874+
///
875+
/// (Automatically generated by Diesel.)
876+
id -> Int4,
877+
/// The `version_id` column of the `version_owner_actions` table.
878+
///
879+
/// Its SQL type is `Nullable<Int4>`.
880+
///
881+
/// (Automatically generated by Diesel.)
882+
version_id -> Nullable<Int4>,
883+
/// The `owner_id` column of the `version_owner_actions` table.
884+
///
885+
/// Its SQL type is `Nullable<Int4>`.
886+
///
887+
/// (Automatically generated by Diesel.)
888+
owner_id -> Nullable<Int4>,
889+
/// The `owner_token_id` column of the `version_owner_actions` table.
890+
///
891+
/// Its SQL type is `Nullable<Int4>`.
892+
///
893+
/// (Automatically generated by Diesel.)
894+
owner_token_id -> Nullable<Int4>,
895+
/// The `action` column of the `version_owner_actions` table.
896+
///
897+
/// Its SQL type is `Int4`.
898+
///
899+
/// (Automatically generated by Diesel.)
900+
action -> Int4,
901+
/// The `time` column of the `version_owner_actions` table.
902+
///
903+
/// Its SQL type is `Timestamp`.
904+
///
905+
/// (Automatically generated by Diesel.)
906+
time -> Timestamp,
907+
}
908+
}
909+
863910
table! {
864911
use diesel::sql_types::*;
865912
use diesel_full_text_search::{TsVector as Tsvector};
@@ -982,6 +1029,9 @@ joinable!(recent_crate_downloads -> crates (crate_id));
9821029
joinable!(version_authors -> users (user_id));
9831030
joinable!(version_authors -> versions (version_id));
9841031
joinable!(version_downloads -> versions (version_id));
1032+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
1033+
joinable!(version_owner_actions -> users (owner_id));
1034+
joinable!(version_owner_actions -> versions (version_id));
9851035
joinable!(versions -> crates (crate_id));
9861036
joinable!(versions -> users (published_by));
9871037
joinable!(versions_published_by -> versions (version_id));
@@ -1010,6 +1060,7 @@ allow_tables_to_appear_in_same_query!(
10101060
users,
10111061
version_authors,
10121062
version_downloads,
1063+
version_owner_actions,
10131064
versions,
10141065
versions_published_by,
10151066
);

src/tasks/dump_db/dump-db.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ counted = "private"
191191
date = "public"
192192
processed = "private"
193193

194+
[version_owner_actions.columns]
195+
id = "private"
196+
version_id = "private"
197+
owner_id = "private"
198+
owner_token_id = "private"
199+
action = "private"
200+
time = "private"
201+
194202
[versions]
195203
dependencies = ["crates", "users"]
196204
[versions.columns]

0 commit comments

Comments
 (0)