add: move upload server to buckets
This commit is contained in:
parent
8116307ba0
commit
75fe720f21
83 changed files with 351 additions and 458 deletions
43
manual_migrations/uploads.js
Normal file
43
manual_migrations/uploads.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import postgres from "npm:postgres";
|
||||
import { parse } from "npm:smol-toml";
|
||||
|
||||
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],
|
||||
});
|
||||
|
||||
const whats = {};
|
||||
const alts = {};
|
||||
|
||||
for (const row of await db`SELECT * FROM uploads;`) {
|
||||
whats[row.id] = row.what.replaceAll('"', "");
|
||||
alts[row.id] = row.alt;
|
||||
}
|
||||
|
||||
await db`ALTER TABLE uploads DROP COLUMN IF EXISTS what;`;
|
||||
await db`ALTER TABLE uploads DROP COLUMN IF EXISTS alt;`;
|
||||
await db`ALTER TABLE uploads ADD COLUMN IF NOT EXISTS bucket TEXT NOT NULL DEFAULT '';`;
|
||||
await db`ALTER TABLE uploads ADD COLUMN IF NOT EXISTS metadata TEXT NOT NULL DEFAULT '';`;
|
||||
|
||||
let i = 0;
|
||||
for (const row of await db`SELECT * FROM uploads;`) {
|
||||
await db`DELETE FROM uploads WHERE id = ${BigInt(row.id)}`;
|
||||
await db`INSERT INTO uploads VALUES (${BigInt(row.id)}, ${BigInt(row.created)}, ${BigInt(row.owner)}, DEFAULT, ${JSON.stringify(
|
||||
{
|
||||
what: whats[row.id],
|
||||
alt: whats[row.alt],
|
||||
},
|
||||
)});`;
|
||||
|
||||
i += 1;
|
||||
console.log(`done ${i}`);
|
||||
}
|
||||
|
||||
await db.end();
|
Loading…
Add table
Add a link
Reference in a new issue