This commit is contained in:
15
scripts/set-admin.ts
Normal file
15
scripts/set-admin.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import postgres from 'postgres';
|
||||
const [userId, role = 'admin'] = process.argv.slice(2);
|
||||
if (!userId || !['admin', 'user'].includes(role))
|
||||
throw new Error('Usage: bun scripts/set-admin.ts <user-id> [admin|user]');
|
||||
if (!process.env.DB_URL) throw new Error('DB_URL is required');
|
||||
const sql = postgres(process.env.DB_URL, { max: 1 });
|
||||
try {
|
||||
const users =
|
||||
await sql`update "user" set role = ${role}, updated_at = now() where id = ${userId} returning id, role`;
|
||||
if (!users.length)
|
||||
throw new Error('User ID not found. Register first and copy the ID from your account page.');
|
||||
console.log(users[0]);
|
||||
} finally {
|
||||
await sql.end();
|
||||
}
|
||||
Reference in New Issue
Block a user