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