Skip to content

Add migration and model for version_owner_actions table #1604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE version_owner_actions;
Original file line number Diff line number Diff line change
@@ -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()
);
2 changes: 2 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -16,6 +17,7 @@ pub use self::version::{NewVersion, Version};

pub mod helpers;

mod action;
mod badge;
pub mod category;
mod crate_owner_invitation;
Expand Down
26 changes: 26 additions & 0 deletions src/models/action.rs
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 1 addition & 1 deletion src/schema.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
51 changes: 51 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int4>`.
///
/// (Automatically generated by Diesel.)
version_id -> Nullable<Int4>,
/// The `owner_id` column of the `version_owner_actions` table.
///
/// Its SQL type is `Nullable<Int4>`.
///
/// (Automatically generated by Diesel.)
owner_id -> Nullable<Int4>,
/// The `owner_token_id` column of the `version_owner_actions` table.
///
/// Its SQL type is `Nullable<Int4>`.
///
/// (Automatically generated by Diesel.)
owner_token_id -> Nullable<Int4>,
/// 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};
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -1010,6 +1060,7 @@ allow_tables_to_appear_in_same_query!(
users,
version_authors,
version_downloads,
version_owner_actions,
versions,
versions_published_by,
);
8 changes: 8 additions & 0 deletions src/tasks/dump_db/dump-db.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down