Skip to content

Commit b62a0ac

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 7ef5d56 commit b62a0ac

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
@@ -78,7 +78,7 @@ index df884e4..18e08cd 100644
7878
joinable!(version_authors -> users (user_id));
7979
joinable!(version_authors -> versions (version_id));
8080
joinable!(version_downloads -> versions (version_id));
81-
joinable!(versions -> crates (crate_id));
81+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
8282

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

src/schema.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,53 @@ table! {
820820
}
821821
}
822822

823+
table! {
824+
use diesel::sql_types::*;
825+
use diesel_full_text_search::{TsVector as Tsvector};
826+
827+
/// Representation of the `version_owner_actions` table.
828+
///
829+
/// (Automatically generated by Diesel.)
830+
version_owner_actions (id) {
831+
/// The `id` column of the `version_owner_actions` table.
832+
///
833+
/// Its SQL type is `Int4`.
834+
///
835+
/// (Automatically generated by Diesel.)
836+
id -> Int4,
837+
/// The `version_id` column of the `version_owner_actions` table.
838+
///
839+
/// Its SQL type is `Nullable<Int4>`.
840+
///
841+
/// (Automatically generated by Diesel.)
842+
version_id -> Nullable<Int4>,
843+
/// The `owner_id` column of the `version_owner_actions` table.
844+
///
845+
/// Its SQL type is `Nullable<Int4>`.
846+
///
847+
/// (Automatically generated by Diesel.)
848+
owner_id -> Nullable<Int4>,
849+
/// The `owner_token_id` column of the `version_owner_actions` table.
850+
///
851+
/// Its SQL type is `Nullable<Int4>`.
852+
///
853+
/// (Automatically generated by Diesel.)
854+
owner_token_id -> Nullable<Int4>,
855+
/// The `action` column of the `version_owner_actions` table.
856+
///
857+
/// Its SQL type is `Int4`.
858+
///
859+
/// (Automatically generated by Diesel.)
860+
action -> Int4,
861+
/// The `time` column of the `version_owner_actions` table.
862+
///
863+
/// Its SQL type is `Timestamp`.
864+
///
865+
/// (Automatically generated by Diesel.)
866+
time -> Timestamp,
867+
}
868+
}
869+
823870
table! {
824871
use diesel::sql_types::*;
825872
use diesel_full_text_search::{TsVector as Tsvector};
@@ -939,6 +986,9 @@ joinable!(recent_crate_downloads -> crates (crate_id));
939986
joinable!(version_authors -> users (user_id));
940987
joinable!(version_authors -> versions (version_id));
941988
joinable!(version_downloads -> versions (version_id));
989+
joinable!(version_owner_actions -> api_tokens (owner_token_id));
990+
joinable!(version_owner_actions -> users (owner_id));
991+
joinable!(version_owner_actions -> versions (version_id));
942992
joinable!(versions -> crates (crate_id));
943993
joinable!(versions -> users (published_by));
944994
joinable!(versions_published_by -> versions (version_id));
@@ -965,6 +1015,7 @@ allow_tables_to_appear_in_same_query!(
9651015
users,
9661016
version_authors,
9671017
version_downloads,
1018+
version_owner_actions,
9681019
versions,
9691020
versions_published_by,
9701021
);

0 commit comments

Comments
 (0)