v3: fixed docker image, updated locales
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 39s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 39s
This commit is contained in:
27
api/db/migrations/0001_comment_likes.ts
Normal file
27
api/db/migrations/0001_comment_likes.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { DatabaseSync } from "node:sqlite";
|
||||
|
||||
// Idempotent: safe to run against a fresh db (already created from schema.sql
|
||||
// with these columns/tables) or an existing one that predates them.
|
||||
export function up(db: DatabaseSync): void {
|
||||
const commentCols = db.prepare(`PRAGMA table_info(comments);`).all() as {
|
||||
name: string;
|
||||
}[];
|
||||
if (!commentCols.some((c) => c.name === "like_count")) {
|
||||
db.exec(
|
||||
`ALTER TABLE comments ADD COLUMN like_count INTEGER NOT NULL DEFAULT 0;`,
|
||||
);
|
||||
}
|
||||
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS comment_likes (
|
||||
comment_id TEXT NOT NULL,
|
||||
user_id TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
PRIMARY KEY (comment_id, user_id),
|
||||
FOREIGN KEY (comment_id) REFERENCES comments(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);`);
|
||||
|
||||
db.exec(
|
||||
`CREATE INDEX IF NOT EXISTS idx_comment_likes_user ON comment_likes(user_id);`,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user