mirror of
https://github.com/4ev-link/4ev.link.git
synced 2026-01-13 16:18:05 +00:00
Feat: Migration script to add banned_until column
This commit is contained in:
19
functions/api/admin/migrate-users-v2.js
Normal file
19
functions/api/admin/migrate-users-v2.js
Normal file
@@ -0,0 +1,19 @@
|
||||
export async function onRequestPost({ request, env }) {
|
||||
try {
|
||||
const { admin_pass } = await request.json();
|
||||
if (admin_pass !== env.ADMIN_PASS) return new Response("Unauthorized", { status: 401 });
|
||||
|
||||
// Add banned_until column (INTEGER for timestamp)
|
||||
try {
|
||||
await env.D1_EV.exec(`ALTER TABLE users ADD COLUMN banned_until INTEGER;`);
|
||||
return new Response("Migration v2 (users) successful: Added banned_until.");
|
||||
} catch (e) {
|
||||
if (e.message.includes("duplicate column")) {
|
||||
return new Response("Migration already applied.");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
} catch (e) {
|
||||
return new Response(e.message, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user