add: store avatars and banners in uploads
This commit is contained in:
parent
1e50ace8b2
commit
dbed2b2457
36 changed files with 211 additions and 363 deletions
54
manual_migrations/avatars.js
Normal file
54
manual_migrations/avatars.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
import postgres from "npm:postgres";
|
||||
import { parse } from "npm:smol-toml";
|
||||
import { readdir, rename } from "node:fs/promises";
|
||||
|
||||
const config = parse(await Deno.readTextFile(Deno.cwd() + "/tetratto.toml"), {
|
||||
integersAsBigInt: true,
|
||||
});
|
||||
|
||||
const db = postgres({
|
||||
user: config.database.user,
|
||||
password: config.database.password,
|
||||
database: config.database.name,
|
||||
hostname: config.database.url.split(":")[0],
|
||||
port: config.database.url.split(":")[1],
|
||||
});
|
||||
|
||||
let i = 0;
|
||||
for (const fname of await readdir(Deno.cwd() + "/media/avatars")) {
|
||||
const [uid, type] = fname.split(".");
|
||||
|
||||
await db`INSERT INTO uploads VALUES (${BigInt(uid)}, ${BigInt(new Date().getTime())}, ${BigInt(uid)}, 'avatars', ${JSON.stringify(
|
||||
{
|
||||
what: type.charAt(0).toUpperCase() + type.slice(1),
|
||||
},
|
||||
)});`;
|
||||
|
||||
await rename(
|
||||
Deno.cwd() + "/media/avatars/" + fname,
|
||||
Deno.cwd() + "/media/uploads/avatars." + fname,
|
||||
);
|
||||
|
||||
i += 1;
|
||||
console.log(`done ${i}`);
|
||||
}
|
||||
|
||||
for (const fname of await readdir(Deno.cwd() + "/media/banners")) {
|
||||
const [uid, type] = fname.split(".");
|
||||
|
||||
await db`INSERT INTO uploads VALUES (${BigInt(uid)}, ${BigInt(new Date().getTime())}, ${BigInt(uid)}, 'banners', ${JSON.stringify(
|
||||
{
|
||||
what: type.charAt(0).toUpperCase() + type.slice(1),
|
||||
},
|
||||
)});`;
|
||||
|
||||
await rename(
|
||||
Deno.cwd() + "/media/banners/" + fname,
|
||||
Deno.cwd() + "/media/uploads/banners." + fname,
|
||||
);
|
||||
|
||||
i += 1;
|
||||
console.log(`done ${i}`);
|
||||
}
|
||||
|
||||
await db.end();
|
4
manual_migrations/uploads_pkey.sql
Normal file
4
manual_migrations/uploads_pkey.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE uploads
|
||||
DROP CONSTRAINT uploads_pkey;
|
||||
|
||||
ALTER TABLE uploads ADD CONSTRAINT uploads_pkey PRIMARY KEY (id, bucket);
|
Loading…
Add table
Add a link
Reference in a new issue