1
Fork 0

core: Fix schema

This commit is contained in:
Steffo 2024-11-16 06:45:58 +01:00
parent c83fdc43e6
commit 7f392bef36
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
3 changed files with 15 additions and 9 deletions

View file

@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS meta_subjects (
id UUID DEFAULT gen_random_uuid(), id UUID DEFAULT gen_random_uuid(),
document BPCHAR NOT NULL, document BPCHAR NOT NULL,
pattern BPCHAR NOT NULL, pattern BPCHAR NOT NULL,
redirect BPCHAR NOT NULL, redirect BPCHAR,
PRIMARY KEY (id) PRIMARY KEY (id)
); );

View file

@ -1,4 +1,4 @@
use diesel::{Associations, Identifiable, Insertable, QueryResult, Queryable, QueryableByName, Selectable}; use diesel::{Associations, Identifiable, Insertable, QueryResult, Queryable, QueryableByName, Selectable, pg::Pg};
use diesel_async::AsyncPgConnection; use diesel_async::AsyncPgConnection;
use uuid::Uuid; use uuid::Uuid;
use super::schema; use super::schema;
@ -6,6 +6,7 @@ use super::schema;
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)] #[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
#[diesel(table_name = schema::meta_subjects)] #[diesel(table_name = schema::meta_subjects)]
#[diesel(check_for_backend(Pg))]
pub struct MetaSubject { pub struct MetaSubject {
pub id: Uuid, pub id: Uuid,
pub document: String, pub document: String,
@ -15,6 +16,7 @@ pub struct MetaSubject {
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)] #[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
#[diesel(table_name = schema::meta_aliases)] #[diesel(table_name = schema::meta_aliases)]
#[diesel(check_for_backend(Pg))]
pub struct MetaAlias { pub struct MetaAlias {
pub id: Uuid, pub id: Uuid,
pub document: String, pub document: String,
@ -24,6 +26,7 @@ pub struct MetaAlias {
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)] #[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
#[diesel(table_name = schema::meta_links)] #[diesel(table_name = schema::meta_links)]
#[diesel(check_for_backend(Pg))]
pub struct MetaLink { pub struct MetaLink {
pub id: Uuid, pub id: Uuid,
pub document: String, pub document: String,
@ -37,6 +40,7 @@ pub struct MetaLink {
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable, Associations)] #[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable, Associations)]
#[diesel(belongs_to(MetaLink))] #[diesel(belongs_to(MetaLink))]
#[diesel(table_name = schema::meta_link_properties)] #[diesel(table_name = schema::meta_link_properties)]
#[diesel(check_for_backend(Pg))]
pub struct MetaLinkProperty { pub struct MetaLinkProperty {
pub id: Uuid, pub id: Uuid,
pub meta_link_id: Uuid, pub meta_link_id: Uuid,
@ -47,6 +51,7 @@ pub struct MetaLinkProperty {
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable, Associations)] #[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable, Associations)]
#[diesel(belongs_to(MetaLink))] #[diesel(belongs_to(MetaLink))]
#[diesel(table_name = schema::meta_link_titles)] #[diesel(table_name = schema::meta_link_titles)]
#[diesel(check_for_backend(Pg))]
pub struct MetaLinkTitle { pub struct MetaLinkTitle {
pub id: Uuid, pub id: Uuid,
pub meta_link_id: Uuid, pub meta_link_id: Uuid,
@ -56,6 +61,7 @@ pub struct MetaLinkTitle {
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)] #[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
#[diesel(table_name = schema::meta_properties)] #[diesel(table_name = schema::meta_properties)]
#[diesel(check_for_backend(Pg))]
pub struct MetaProperty { pub struct MetaProperty {
pub id: Uuid, pub id: Uuid,
pub document: String, pub document: String,
@ -65,7 +71,7 @@ pub struct MetaProperty {
} }
impl MetaSubject { impl MetaSubject {
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaSubject>> { pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use schema::meta_subjects::dsl::*; use schema::meta_subjects::dsl::*;
@ -83,7 +89,7 @@ impl MetaSubject {
} }
impl MetaAlias { impl MetaAlias {
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaAlias>> { pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use schema::meta_aliases::dsl::*; use schema::meta_aliases::dsl::*;
@ -101,7 +107,7 @@ impl MetaAlias {
} }
impl MetaLink { impl MetaLink {
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaLink>> { pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use schema::meta_links::dsl::*; use schema::meta_links::dsl::*;
@ -119,7 +125,7 @@ impl MetaLink {
} }
impl MetaLinkProperty { impl MetaLinkProperty {
pub async fn query_by_link(conn: &mut AsyncPgConnection, links: &[MetaLink]) -> QueryResult<Vec<MetaLinkProperty>> { pub async fn query_by_link(conn: &mut AsyncPgConnection, links: &[MetaLink]) -> QueryResult<Vec<Self>> {
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -130,7 +136,7 @@ impl MetaLinkProperty {
} }
impl MetaLinkTitle { impl MetaLinkTitle {
pub async fn query_by_link(conn: &mut AsyncPgConnection, links: &[MetaLink]) -> QueryResult<Vec<MetaLinkTitle>> { pub async fn query_by_link(conn: &mut AsyncPgConnection, links: &[MetaLink]) -> QueryResult<Vec<Self>> {
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -141,7 +147,7 @@ impl MetaLinkTitle {
} }
impl MetaProperty { impl MetaProperty {
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaProperty>> { pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use schema::meta_properties::dsl::*; use schema::meta_properties::dsl::*;

View file

@ -55,7 +55,7 @@ diesel::table! {
id -> Uuid, id -> Uuid,
document -> Bpchar, document -> Bpchar,
pattern -> Bpchar, pattern -> Bpchar,
redirect -> Bpchar, redirect -> Nullable<Bpchar>,
} }
} }