diff --git a/migrations/2019-01-26-090348_create_version_owner_actions/down.sql b/migrations/2019-01-26-090348_create_version_owner_actions/down.sql new file mode 100644 index 00000000000..f3f9004202f --- /dev/null +++ b/migrations/2019-01-26-090348_create_version_owner_actions/down.sql @@ -0,0 +1 @@ +DROP TABLE version_owner_actions; diff --git a/migrations/2019-01-26-090348_create_version_owner_actions/up.sql b/migrations/2019-01-26-090348_create_version_owner_actions/up.sql new file mode 100644 index 00000000000..7149e80f239 --- /dev/null +++ b/migrations/2019-01-26-090348_create_version_owner_actions/up.sql @@ -0,0 +1,8 @@ +CREATE TABLE version_owner_actions ( + id SERIAL PRIMARY KEY, + version_id INTEGER REFERENCES versions(id) ON DELETE CASCADE, + owner_id INTEGER REFERENCES users(id), + owner_token_id INTEGER REFERENCES api_tokens(id), + action INTEGER NOT NULL, + time TIMESTAMP NOT NULL DEFAULT now() +); diff --git a/src/models.rs b/src/models.rs index 9968177d294..806d7c91dc9 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,3 +1,4 @@ +pub use self::action::{VersionAction, VersionOwnerAction}; pub use self::badge::{Badge, CrateBadge, MaintenanceStatus}; pub use self::category::{Category, CrateCategory, NewCategory}; pub use self::crate_owner_invitation::{CrateOwnerInvitation, NewCrateOwnerInvitation}; @@ -16,6 +17,7 @@ pub use self::version::{NewVersion, Version}; pub mod helpers; +mod action; mod badge; pub mod category; mod crate_owner_invitation; diff --git a/src/models/action.rs b/src/models/action.rs new file mode 100644 index 00000000000..474bc252ab8 --- /dev/null +++ b/src/models/action.rs @@ -0,0 +1,26 @@ +use chrono::NaiveDateTime; + +use crate::models::{ApiToken, User, Version}; +use crate::schema::*; + +#[derive(Debug, Clone, Copy)] +#[repr(u32)] +pub enum VersionAction { + Publish = 0, + Yank = 1, + Unyank = 2, +} + +#[derive(Debug, Clone, Copy, Queryable, Identifiable, Associations)] +#[belongs_to(Version)] +#[belongs_to(User, foreign_key = "owner_id")] +#[belongs_to(ApiToken, foreign_key = "owner_token_id")] +#[table_name = "version_owner_actions"] +pub struct VersionOwnerAction { + pub id: i32, + pub version_id: i32, + pub owner_id: i32, + pub owner_token_id: i32, + pub action: VersionAction, + pub time: NaiveDateTime, +} diff --git a/src/schema.patch b/src/schema.patch index 15fcc9660be..19d60a0ec6d 100644 --- a/src/schema.patch +++ b/src/schema.patch @@ -80,7 +80,7 @@ index df884e4..18e08cd 100644 joinable!(version_authors -> users (user_id)); joinable!(version_authors -> versions (version_id)); joinable!(version_downloads -> versions (version_id)); - joinable!(versions -> crates (crate_id)); + joinable!(version_owner_actions -> api_tokens (owner_token_id)); @@ -913,13 +935,14 @@ allow_tables_to_appear_in_same_query!( emails, diff --git a/src/schema.rs b/src/schema.rs index 5226269f5c9..6b692eeada9 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -860,6 +860,53 @@ table! { } } +table! { + use diesel::sql_types::*; + use diesel_full_text_search::{TsVector as Tsvector}; + + /// Representation of the `version_owner_actions` table. + /// + /// (Automatically generated by Diesel.) + version_owner_actions (id) { + /// The `id` column of the `version_owner_actions` table. + /// + /// Its SQL type is `Int4`. + /// + /// (Automatically generated by Diesel.) + id -> Int4, + /// The `version_id` column of the `version_owner_actions` table. + /// + /// Its SQL type is `Nullable`. + /// + /// (Automatically generated by Diesel.) + version_id -> Nullable, + /// The `owner_id` column of the `version_owner_actions` table. + /// + /// Its SQL type is `Nullable`. + /// + /// (Automatically generated by Diesel.) + owner_id -> Nullable, + /// The `owner_token_id` column of the `version_owner_actions` table. + /// + /// Its SQL type is `Nullable`. + /// + /// (Automatically generated by Diesel.) + owner_token_id -> Nullable, + /// The `action` column of the `version_owner_actions` table. + /// + /// Its SQL type is `Int4`. + /// + /// (Automatically generated by Diesel.) + action -> Int4, + /// The `time` column of the `version_owner_actions` table. + /// + /// Its SQL type is `Timestamp`. + /// + /// (Automatically generated by Diesel.) + time -> Timestamp, + } +} + table! { use diesel::sql_types::*; use diesel_full_text_search::{TsVector as Tsvector}; @@ -982,6 +1029,9 @@ joinable!(recent_crate_downloads -> crates (crate_id)); joinable!(version_authors -> users (user_id)); joinable!(version_authors -> versions (version_id)); joinable!(version_downloads -> versions (version_id)); +joinable!(version_owner_actions -> api_tokens (owner_token_id)); +joinable!(version_owner_actions -> users (owner_id)); +joinable!(version_owner_actions -> versions (version_id)); joinable!(versions -> crates (crate_id)); joinable!(versions -> users (published_by)); joinable!(versions_published_by -> versions (version_id)); @@ -1010,6 +1060,7 @@ allow_tables_to_appear_in_same_query!( users, version_authors, version_downloads, + version_owner_actions, versions, versions_published_by, ); diff --git a/src/tasks/dump_db/dump-db.toml b/src/tasks/dump_db/dump-db.toml index 38318037c95..12302c891ba 100644 --- a/src/tasks/dump_db/dump-db.toml +++ b/src/tasks/dump_db/dump-db.toml @@ -191,6 +191,14 @@ counted = "private" date = "public" processed = "private" +[version_owner_actions.columns] +id = "private" +version_id = "private" +owner_id = "private" +owner_token_id = "private" +action = "private" +time = "private" + [versions] dependencies = ["crates", "users"] [versions.columns]