Initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env tsx
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import * as schema from '../src/schemas/database/schema';
|
||||
import { hashPassword } from '../src/lib/utils/passwordHash';
|
||||
|
||||
// Load environment variables from .env file
|
||||
config();
|
||||
|
||||
async function seedAdmin() {
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
if (!databaseUrl) {
|
||||
throw new Error('DATABASE_URL environment variable is not set');
|
||||
}
|
||||
|
||||
console.log('👤 Starting admin user seeding...');
|
||||
|
||||
const client = postgres(databaseUrl);
|
||||
const db = drizzle(client, { schema });
|
||||
|
||||
try {
|
||||
// Create admin user
|
||||
console.log('👤 Creating admin user...');
|
||||
const adminPasswordHash = await hashPassword('admin123');
|
||||
|
||||
const adminUser = await db
|
||||
.insert(schema.managementUsers)
|
||||
.values({
|
||||
firstName: 'Admin',
|
||||
lastName: 'User',
|
||||
username: 'admin',
|
||||
passwordHash: adminPasswordHash,
|
||||
role: 'ADMIN',
|
||||
enabled: true
|
||||
})
|
||||
.returning()
|
||||
.onConflictDoNothing();
|
||||
|
||||
if (adminUser.length > 0) {
|
||||
console.log('✅ Admin user created with username: admin, password: admin123');
|
||||
} else {
|
||||
console.log('ℹ️ Admin user already exists');
|
||||
}
|
||||
|
||||
console.log('🎉 Admin user seeding completed successfully!');
|
||||
} catch (error) {
|
||||
console.error('❌ Error during admin seeding:', error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await client.end();
|
||||
}
|
||||
}
|
||||
|
||||
seedAdmin().catch((error) => {
|
||||
console.error('❌ Admin seeding failed:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user