v3: added emoji picker, various bug and layout fixes
This commit is contained in:
@@ -8,41 +8,10 @@ import {
|
||||
type RichContent,
|
||||
type User,
|
||||
} from "./interfaces.ts";
|
||||
import { makeSlug } from "../lib/slugify.ts";
|
||||
|
||||
export const db = new DatabaseSync("api/sql/gerbeur.db");
|
||||
db.exec("PRAGMA foreign_keys = ON;");
|
||||
|
||||
// Add columns to existing tables if missing (idempotent migrations)
|
||||
for (
|
||||
const [table, col, def] of [
|
||||
["dumps", "updated_at", "TEXT"],
|
||||
["users", "updated_at", "TEXT"],
|
||||
["playlists", "updated_at", "TEXT"],
|
||||
["comments", "updated_at", "TEXT"],
|
||||
["dumps", "slug", "TEXT"],
|
||||
["playlists", "slug", "TEXT"],
|
||||
] as [string, string, string][]
|
||||
) {
|
||||
const cols = db.prepare(`PRAGMA table_info(${table})`).all() as {
|
||||
name: string;
|
||||
}[];
|
||||
if (!cols.some((c) => c.name === col)) {
|
||||
db.exec(`ALTER TABLE ${table} ADD COLUMN ${col} ${def};`);
|
||||
}
|
||||
}
|
||||
|
||||
// Backfill slugs for any records created before this migration
|
||||
for (const table of ["dumps", "playlists"] as const) {
|
||||
const rows = db.prepare(
|
||||
`SELECT id, title FROM ${table} WHERE slug IS NULL;`,
|
||||
).all() as { id: string; title: string }[];
|
||||
const update = db.prepare(`UPDATE ${table} SET slug = ? WHERE id = ?;`);
|
||||
for (const row of rows) {
|
||||
update.run(makeSlug(row.title, row.id), row.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Purge expired unused invites on startup
|
||||
db.prepare(
|
||||
`DELETE FROM invites WHERE used_at IS NULL AND created_at < datetime('now', '-7 days');`,
|
||||
|
||||
@@ -363,6 +363,7 @@ export interface OnlineUser {
|
||||
userId: string;
|
||||
username: string;
|
||||
hasAvatar: boolean;
|
||||
avatarVersion?: number;
|
||||
}
|
||||
|
||||
export interface WelcomeMessage {
|
||||
|
||||
Reference in New Issue
Block a user