add iri column
This commit is contained in:
parent
93182705d9
commit
4f542571e0
11 changed files with 35 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
CREATE TABLE accounts (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
iri VARCHAR,
|
||||
name VARCHAR NOT NULL,
|
||||
domain VARCHAR NOT NULL,
|
||||
display_name VARCHAR DEFAULT NULL,
|
||||
|
@ -7,4 +8,5 @@ CREATE TABLE accounts (
|
|||
updated_at TIMESTAMP NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX index_accounts_on_iri ON accounts (iri);
|
||||
CREATE UNIQUE INDEX index_accounts_on_name_and_domain ON accounts (name, domain);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
CREATE TABLE notes (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
account_id BIGINT REFERENCES accounts (id),
|
||||
uri VARCHAR,
|
||||
iri VARCHAR,
|
||||
content TEXT NOT NULL,
|
||||
source TEXT DEFAULT NULL,
|
||||
summary TEXT DEFAULT NULL,
|
||||
|
@ -11,5 +11,5 @@ CREATE TABLE notes (
|
|||
);
|
||||
|
||||
CREATE INDEX index_notes_on_account_id ON notes (account_id);
|
||||
CREATE UNIQUE INDEX index_notes_on_uri ON notes (uri);
|
||||
CREATE UNIQUE INDEX index_notes_on_iri ON notes (iri);
|
||||
CREATE INDEX index_notes_on_created_at ON notes (created_at);
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
CREATE TABLE follows (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
iri VARCHAR,
|
||||
follower_id BIGINT REFERENCES accounts (id) ON DELETE CASCADE,
|
||||
followee_id BIGINT REFERENCES accounts (id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP DEFAULT now()
|
||||
created_at TIMESTAMP NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX index_follows_on_follower_id ON follows (follower_id);
|
||||
CREATE INDEX index_follows_on_followee_id ON follows (followee_id);
|
||||
CREATE UNIQUE INDEX index_follows_on_iri ON follows(iri);
|
||||
CREATE UNIQUE INDEX index_follows_on_follower_id_and_followee_id ON follows (follower_id, followee_id);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
CREATE TABLE likes (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
iri VARCHAR,
|
||||
note_id BIGINT REFERENCES notes (id) ON DELETE CASCADE,
|
||||
account_id BIGINT REFERENCES accounts (id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX index_likes_on_note_id ON likes (note_id);
|
||||
CREATE INDEX index_likes_on_account_id ON likes (account_id);
|
||||
CREATE UNIQUE INDEX index_likes_on_iri ON likes (iri);
|
||||
CREATE UNIQUE INDEX index_likes_on_note_id_and_account_id ON likes (note_id, account_id);
|
||||
|
|
|
@ -30,10 +30,11 @@ impl PgAccountDataSource {
|
|||
{
|
||||
let new = new.into();
|
||||
let account: Account = sqlx::query_as(
|
||||
"INSERT INTO accounts (name, domain, display_name)
|
||||
VALUES ($1, $2, $3)
|
||||
"INSERT INTO accounts (iri, name, domain, display_name)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING *",
|
||||
)
|
||||
.bind(new.iri)
|
||||
.bind(new.name)
|
||||
.bind(new.domain)
|
||||
.bind(new.display_name)
|
||||
|
|
|
@ -29,8 +29,11 @@ impl PgFollowDataSource {
|
|||
{
|
||||
let new = new.into();
|
||||
let follow: Follow = sqlx::query_as(
|
||||
"INSERT INTO follows (follower_id, followee_id) VALUES ($1, $2) RETURNING *",
|
||||
"INSERT INTO follows (iri, follower_id, followee_id)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING *",
|
||||
)
|
||||
.bind(new.iri)
|
||||
.bind(new.follower_id)
|
||||
.bind(new.followee_id)
|
||||
.fetch_one(&self.pool)
|
||||
|
|
|
@ -30,8 +30,12 @@ impl PgLikeDataSource {
|
|||
E: Into<Error>,
|
||||
{
|
||||
let new = new.try_into().map_err(|e| e.into())?.inner();
|
||||
let like: Like =
|
||||
sqlx::query_as("INSERT INTO likes (note_id, account_id) VALUES ($1, $2) RETURNING *")
|
||||
let like: Like = sqlx::query_as(
|
||||
"INSERT INTO likes (iri, note_id, account_id)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING *",
|
||||
)
|
||||
.bind(new.iri)
|
||||
.bind(new.note_id)
|
||||
.bind(new.account_id)
|
||||
.fetch_one(&self.pool)
|
||||
|
|
|
@ -51,7 +51,7 @@ impl PgNoteDataSource {
|
|||
let note: Note = sqlx::query_as(
|
||||
"INSERT INTO notes (
|
||||
account_id,
|
||||
uri,
|
||||
iri,
|
||||
content,
|
||||
source,
|
||||
summary,
|
||||
|
@ -60,7 +60,7 @@ impl PgNoteDataSource {
|
|||
RETURNING *",
|
||||
)
|
||||
.bind(new.account_id)
|
||||
.bind(new.uri)
|
||||
.bind(new.iri)
|
||||
.bind(new.content)
|
||||
.bind(new.source)
|
||||
.bind(new.summary)
|
||||
|
|
|
@ -8,6 +8,7 @@ use crate::util::validate::{ResultBuilder, Validate};
|
|||
#[derive(Deserialize, Serialize, FromRow)]
|
||||
pub struct Account {
|
||||
pub id: Id,
|
||||
pub iri: Option<String>,
|
||||
pub name: String,
|
||||
pub domain: String,
|
||||
pub display_name: Option<String>,
|
||||
|
@ -16,6 +17,7 @@ pub struct Account {
|
|||
}
|
||||
|
||||
pub struct NewAccount {
|
||||
pub iri: Option<String>,
|
||||
pub name: String,
|
||||
pub domain: String,
|
||||
pub display_name: Option<String>,
|
||||
|
|
|
@ -8,12 +8,14 @@ use crate::util::validate::{ResultBuilder, Validate};
|
|||
#[derive(Deserialize, Serialize, FromRow)]
|
||||
pub struct Follow {
|
||||
pub id: Id,
|
||||
pub iri: Option<String>,
|
||||
pub follower_id: Id,
|
||||
pub followee_id: Id,
|
||||
pub created_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
pub struct NewFollow {
|
||||
pub iri: Option<String>,
|
||||
pub follower_id: Id,
|
||||
pub followee_id: Id,
|
||||
}
|
||||
|
|
|
@ -8,12 +8,14 @@ use crate::util::validate::{ResultBuilder, Validate};
|
|||
#[derive(Deserialize, Serialize, FromRow)]
|
||||
pub struct Like {
|
||||
pub id: Id,
|
||||
pub iri: Option<String>,
|
||||
pub note_id: Id,
|
||||
pub account_id: Id,
|
||||
pub created_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
pub struct NewLike {
|
||||
pub iri: Option<String>,
|
||||
pub note_id: Id,
|
||||
pub account_id: Id,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue