Fixed posts not saving correctly after DB migration

This commit is contained in:
Max Nuding 2023-04-13 16:18:30 +02:00
parent 8d3a23ee88
commit 4e7196182c
Signed by: phlaym
GPG Key ID: A06651BAB6777237
2 changed files with 11 additions and 15 deletions

View File

@ -24,5 +24,4 @@ export interface Account {
display_name: string;
url: string;
avatar: string;
avatar_static: string;
}

View File

@ -201,24 +201,22 @@ export async function savePost(post: Post): Promise<undefined> {
const account = post.account;
db.run(
`
INSERT INTO accounts (id, acct, username, display_name, url, avatar, avatar_static)
VALUES(?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id)
INSERT INTO accounts (id, acct, username, display_name, url, avatar)
VALUES(?, ?, ?, ?, ?, ?)
ON CONFLICT(url)
DO UPDATE SET
acct=excluded.acct,
username=excluded.username,
display_name=excluded.display_name,
url=excluded.url,
avatar=excluded.avatar,
avatar_static=excluded.avatar_static;`,
id=excluded.id,
avatar=excluded.avatar;`,
[
account.id,
account.acct,
account.username,
account.display_name,
account.url,
account.avatar,
account.avatar_static
account.avatar
],
(err) => {
if (err !== null) {
@ -229,12 +227,12 @@ export async function savePost(post: Post): Promise<undefined> {
db.run(
`
INSERT INTO posts (id, content, created_at, url, account_id)
VALUES (?, ?, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET
VALUES (?, ?, ?, ?, ?) ON CONFLICT(url) DO UPDATE SET
content=excluded.content,
created_at=excluded.created_at,
url=excluded.url,
id=excluded.id,
account_id=excluded.account_id;`,
[post.id, post.content, post.created_at, post.url, post.account.id],
[post.id, post.content, post.created_at, post.url, post.account.url],
(postErr) => {
if (postErr !== null) {
console.error(`Could not insert post ${post.url}`, postErr);
@ -259,7 +257,7 @@ export async function savePost(post: Post): Promise<undefined> {
}
db.run(
'INSERT INTO poststags (post_id, tag_url) VALUES (?, ?)',
[post.id, tag.url],
[post.url, tag.url],
(posttagserr) => {
if (posttagserr !== null) {
console.error(
@ -369,8 +367,7 @@ export async function getPosts(since: string | null, before: string | null, limi
username: row.username,
display_name: row.display_name,
url: row.account_url,
avatar: row.avatar,
avatar_static: ''
avatar: row.avatar
} as Account
} as Post;
});