Skip to content

Commit e3c6c5f

Browse files
committed
Cleanup preseeded db
1 parent 0c7ab8c commit e3c6c5f

File tree

2 files changed

+32
-55
lines changed

2 files changed

+32
-55
lines changed

playground/pre-seeded-database.db

0 Bytes
Binary file not shown.

playground/src/index.js

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,44 @@
11
module.exports = {
22
async bootstrap({ strapi }) {
3-
console.log('🚀 Bootstrap function called!');
4-
// TODO: clean up this boostrap script
5-
// Only run seeding in development/test environments
6-
if (process.env.NODE_ENV !== 'production') {
7-
try {
8-
console.log('🌱 Starting bootstrap seeding...');
3+
try {
4+
console.log('🚀 Starting seeding...');
95

10-
// Check if admin user exists
11-
const adminUser = await strapi.query('admin::user').findOne({
12-
where: { email: '[email protected]' }
13-
});
14-
15-
if (!adminUser) {
16-
// Create admin user using Strapi's admin service
17-
const adminUserService = strapi.service('admin::user');
18-
const superAdminRole = await strapi.query('admin::role').findOne({
19-
where: { code: 'strapi-super-admin' }
20-
});
6+
// Check if admin user exists
7+
const adminUser = await strapi.query('admin::user').findOne({
8+
where: { email: '[email protected]' }
9+
});
2110

22-
await adminUserService.create({
23-
firstname: 'Super Admin User',
24-
25-
password: 'password',
26-
isActive: true,
27-
roles: [superAdminRole.id],
28-
});
29-
console.log('✅ Admin user created');
30-
} else {
31-
console.log('✅ Admin user already exists');
32-
// Update the password if it's not hashed (for existing users)
33-
if (adminUser.password === 'password') {
34-
const adminUserService = strapi.service('admin::user');
35-
await adminUserService.updateById(adminUser.id, {
36-
password: 'password'
37-
});
38-
console.log('✅ Admin user password updated with proper hash');
39-
}
40-
}
41-
42-
// Check if test API token exists
43-
const existingToken = await strapi.query('admin::api-token').findOne({
44-
where: { name: 'cypress-test-token' }
11+
if (!adminUser) {
12+
// Create admin user using Strapi's admin service
13+
const adminUserService = strapi.service('admin::user');
14+
const superAdminRole = await strapi.query('admin::role').findOne({
15+
where: { code: 'strapi-super-admin' }
4516
});
4617

47-
if (!existingToken) {
48-
// Create API token for Cypress tests
49-
const tokenService = strapi.service('admin::api-token');
50-
const token = await tokenService.create({
51-
name: 'cypress-test-token',
52-
description: 'API token for Cypress tests',
53-
type: 'full-access',
18+
await adminUserService.create({
19+
firstname: 'Super Admin User',
20+
21+
password: 'password',
22+
isActive: true,
23+
roles: [superAdminRole.id],
24+
});
25+
console.log('✅ Admin user created');
26+
} else {
27+
console.log('✅ Admin user already exists');
28+
// Update the password if it's not hashed (for existing users)
29+
if (adminUser.password === 'password') {
30+
const adminUserService = strapi.service('admin::user');
31+
await adminUserService.updateById(adminUser.id, {
32+
password: 'password'
5433
});
55-
console.log('✅ Cypress test token created:', token.accessKey);
56-
} else {
57-
console.log('✅ Cypress test token already exists');
34+
console.log('✅ Admin user password updated with proper hash');
5835
}
59-
60-
console.log('🌱 Bootstrap seeding completed successfully');
61-
} catch (error) {
62-
console.error('❌ Bootstrap seeding failed:', error.message);
63-
console.error('Error details:', error);
6436
}
37+
38+
console.log('🌱 Seeding completed!');
39+
} catch (error) {
40+
console.error('❌ Seeding failed:', error.message);
41+
console.error('Error details:', error);
6542
}
6643
},
6744
};

0 commit comments

Comments
 (0)