Skip to content

Commit

Permalink
db_schema crate is close to building?
Browse files Browse the repository at this point in the history
  • Loading branch information
chusteven committed May 11, 2022
1 parent a523e4e commit bf8f55d
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions crates/db_schema/src/aggregates/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::schema::{
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "comment_aggregates")]
#[cfg_attr(feature = "full", belongs_to(crate::source::comment::Comment))]
pub struct CommentAggregates {
pub id: i32,
pub comment_id: CommentId,
Expand All @@ -25,6 +26,7 @@ pub struct CommentAggregates {
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "community_aggregates")]
#[cfg_attr(feature = "full", belongs_to(crate::source::community::Community))]
pub struct CommunityAggregates {
pub id: i32,
pub community_id: CommunityId,
Expand All @@ -41,6 +43,7 @@ pub struct CommunityAggregates {
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person_aggregates")]
#[cfg_attr(feature = "full", belongs_to(crate::source::person::Person))]
pub struct PersonAggregates {
pub id: i32,
pub person_id: PersonId,
Expand All @@ -53,6 +56,7 @@ pub struct PersonAggregates {
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "post_aggregates")]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
pub struct PostAggregates {
pub id: i32,
pub post_id: PostId,
Expand All @@ -69,6 +73,7 @@ pub struct PostAggregates {
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "site_aggregates")]
#[cfg_attr(feature = "full", belongs_to(crate::source::site::Site))]
pub struct SiteAggregates {
pub id: i32,
pub site_id: i32,
Expand Down
4 changes: 2 additions & 2 deletions crates/db_schema/src/source/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct CommentForm {

#[derive(PartialEq, Debug, Clone)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Comment))]
#[cfg_attr(feature = "full", belongs_to(crate::source::comment::Comment))]
#[cfg_attr(feature = "full", table_name = "comment_like")]
pub struct CommentLike {
pub id: i32,
Expand All @@ -91,7 +91,7 @@ pub struct CommentLikeForm {

#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Comment))]
#[cfg_attr(feature = "full", belongs_to(crate::source::comment::Comment))]
#[cfg_attr(feature = "full", table_name = "comment_saved")]
pub struct CommentSaved {
pub id: i32,
Expand Down
6 changes: 3 additions & 3 deletions crates/db_schema/src/source/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct CommunityForm {

#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Community))]
#[cfg_attr(feature = "full", belongs_to(crate::source::community::Community))]
#[cfg_attr(feature = "full", table_name = "community_moderator")]
pub struct CommunityModerator {
pub id: i32,
Expand All @@ -100,7 +100,7 @@ pub struct CommunityModeratorForm {

#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Community))]
#[cfg_attr(feature = "full", belongs_to(crate::source::community::Community))]
#[cfg_attr(feature = "full", table_name = "community_person_ban")]
pub struct CommunityPersonBan {
pub id: i32,
Expand All @@ -121,7 +121,7 @@ pub struct CommunityPersonBanForm {

#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Community))]
#[cfg_attr(feature = "full", belongs_to(crate::source::community::Community))]
#[cfg_attr(feature = "full", table_name = "community_follower")]
pub struct CommunityFollower {
pub id: i32,
Expand Down
1 change: 1 addition & 0 deletions crates/db_schema/src/source/person_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::schema::person_block;

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", belongs_to(crate::source::person::Person))]
#[cfg_attr(feature = "full", table_name = "person_block")]
pub struct PersonBlock {
pub id: PersonBlockId,
Expand Down
6 changes: 3 additions & 3 deletions crates/db_schema/src/source/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct PostForm {

#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Post))]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
#[cfg_attr(feature = "full", table_name = "post_like")]
pub struct PostLike {
pub id: i32,
Expand All @@ -76,7 +76,7 @@ pub struct PostLikeForm {

#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Post))]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
#[cfg_attr(feature = "full", table_name = "post_saved")]
pub struct PostSaved {
pub id: i32,
Expand All @@ -94,7 +94,7 @@ pub struct PostSavedForm {

#[derive(PartialEq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Post))]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
#[cfg_attr(feature = "full", table_name = "post_read")]
pub struct PostRead {
pub id: i32,
Expand Down
2 changes: 1 addition & 1 deletion crates/db_schema/src/source/post_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::schema::post_report;

#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))] // Is this the right assoc?
#[cfg_attr(feature = "full", table_name = "post_report")]
pub struct PostReport {
pub id: PostReportId,
Expand Down
1 change: 1 addition & 0 deletions crates/db_schema/src/source/private_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::schema::private_message;

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", belongs_to(crate::source::person::Person, foreign_key = "creator_id"))] // Is this the right assoc?
#[cfg_attr(feature = "full", table_name = "private_message")]
pub struct PrivateMessage {
pub id: PrivateMessageId,
Expand Down
5 changes: 3 additions & 2 deletions crates/db_schema/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::newtypes::DbUrl;
use diesel_migrations::EmbeddedMigrations;
use chrono::NaiveDateTime;
use diesel::{
backend::Backend,
Expand Down Expand Up @@ -65,7 +66,7 @@ pub fn diesel_option_overwrite_to_url(
}
}

embed_migrations!();
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();

pub fn establish_unpooled_connection() -> PgConnection {
let db_url = match get_database_url_from_env() {
Expand All @@ -77,7 +78,7 @@ pub fn establish_unpooled_connection() -> PgConnection {
};
let conn =
PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
embedded_migrations::run(&conn).expect("load migrations");
conn.run_pending_migrations(MIGRATIONS).unwrap();
conn
}

Expand Down

0 comments on commit bf8f55d

Please sign in to comment.