chore: move seeding to onInit and remove redundant seed script
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🧪 QA (push) Successful in 2m15s
Build & Deploy / 🏗️ Build (push) Successful in 3m51s
Build & Deploy / 🚀 Deploy (push) Successful in 21s
Build & Deploy / 🧪 Smoke Test (push) Failing after 1m3s
Build & Deploy / ⚡ Lighthouse (push) Has been skipped
Build & Deploy / ♿ WCAG (push) Has been skipped
Build & Deploy / 🛡️ Quality Gates (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 9s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🧪 QA (push) Successful in 2m15s
Build & Deploy / 🏗️ Build (push) Successful in 3m51s
Build & Deploy / 🚀 Deploy (push) Successful in 21s
Build & Deploy / 🧪 Smoke Test (push) Failing after 1m3s
Build & Deploy / ⚡ Lighthouse (push) Has been skipped
Build & Deploy / ♿ WCAG (push) Has been skipped
Build & Deploy / 🛡️ Quality Gates (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 9s
This commit is contained in:
@@ -358,9 +358,6 @@ jobs:
|
||||
ssh root@alpha.mintel.me "cd $SITE_DIR && docker compose -p '${{ needs.prepare.outputs.project_name }}' --env-file '$ENV_FILE' pull"
|
||||
ssh root@alpha.mintel.me "cd $SITE_DIR && docker compose -p '${{ needs.prepare.outputs.project_name }}' --env-file '$ENV_FILE' up -d --remove-orphans"
|
||||
|
||||
# Automate DB Seeding (Migrations are handled via Payload autoMigrate)
|
||||
ssh root@alpha.mintel.me "cd $SITE_DIR && docker compose -p '${{ needs.prepare.outputs.project_name }}' --env-file '$ENV_FILE' exec -T klz-app pnpm run cms:seed"
|
||||
|
||||
ssh root@alpha.mintel.me "docker system prune -f --filter 'until=24h'"
|
||||
|
||||
- name: 🧹 Post-Deploy Cleanup (Runner)
|
||||
|
||||
2
next-env.d.ts
vendored
2
next-env.d.ts
vendored
@@ -1,6 +1,6 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
import "./.next/types/routes.d.ts";
|
||||
import "./.next/dev/types/routes.d.ts";
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
|
||||
@@ -21,11 +21,17 @@ import { Posts } from './src/payload/collections/Posts';
|
||||
import { FormSubmissions } from './src/payload/collections/FormSubmissions';
|
||||
import { Products } from './src/payload/collections/Products';
|
||||
import { Pages } from './src/payload/collections/Pages';
|
||||
import { seedDatabase } from './src/payload/seed';
|
||||
|
||||
const filename = fileURLToPath(import.meta.url);
|
||||
const dirname = path.dirname(filename);
|
||||
|
||||
export default buildConfig({
|
||||
onInit: async (payload) => {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
await seedDatabase(payload);
|
||||
}
|
||||
},
|
||||
admin: {
|
||||
user: Users.slug,
|
||||
importMap: {
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
import { getPayload } from 'payload';
|
||||
import configPromise from '../payload.config';
|
||||
|
||||
async function seed() {
|
||||
console.log('🌱 Starting PayloadCMS seed process...');
|
||||
|
||||
try {
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
|
||||
// Check if any users exist
|
||||
const { totalDocs } = await payload.find({
|
||||
collection: 'users',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
if (totalDocs === 0) {
|
||||
console.log('👤 No users found. Creating default admin user...');
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
email: 'admin@mintel.me',
|
||||
password: 'klz-admin-setup',
|
||||
firstName: 'KLZ',
|
||||
lastName: 'Admin',
|
||||
role: 'admin',
|
||||
},
|
||||
});
|
||||
console.log('✅ Default admin user created successfully.');
|
||||
} else {
|
||||
console.log(`ℹ️ Database already contains ${totalDocs} users. Skipping user creation.`);
|
||||
}
|
||||
|
||||
// Check if any products exist
|
||||
const { totalDocs: totalProducts } = await payload.find({
|
||||
collection: 'products',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
if (totalProducts === 0) {
|
||||
console.log('📦 No products found. Creating smoke test product (NAY2Y)...');
|
||||
await payload.create({
|
||||
collection: 'products',
|
||||
data: {
|
||||
title: 'NAY2Y Smoke Test',
|
||||
sku: 'SMOKE-TEST-001',
|
||||
slug: 'nay2y',
|
||||
description: 'A dummy product for CI/CD smoke testing and OG image verification.',
|
||||
locale: 'de',
|
||||
categories: [{ category: 'Power Cables' }],
|
||||
_status: 'published',
|
||||
},
|
||||
});
|
||||
console.log('✅ Smoke test product created successfully.');
|
||||
} else {
|
||||
console.log(
|
||||
`ℹ️ Database already contains ${totalProducts} products. Skipping product creation.`,
|
||||
);
|
||||
}
|
||||
|
||||
console.log('✅ PayloadCMS seed completed successfully!');
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to seed PayloadCMS database:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
seed();
|
||||
44
src/payload/seed.ts
Normal file
44
src/payload/seed.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Payload } from 'payload';
|
||||
|
||||
export async function seedDatabase(payload: Payload) {
|
||||
// Check if any users exist
|
||||
const { totalDocs: totalUsers } = await payload.find({
|
||||
collection: 'users',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
if (totalUsers === 0) {
|
||||
payload.logger.info('👤 No users found. Creating default admin user...');
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
email: 'admin@mintel.me',
|
||||
password: 'klz-admin-setup',
|
||||
},
|
||||
});
|
||||
payload.logger.info('✅ Default admin user created successfully.');
|
||||
}
|
||||
|
||||
// Check if any products exist
|
||||
const { totalDocs: totalProducts } = await payload.find({
|
||||
collection: 'products',
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
if (totalProducts === 0) {
|
||||
payload.logger.info('📦 No products found. Creating smoke test product (NAY2Y)...');
|
||||
await payload.create({
|
||||
collection: 'products',
|
||||
data: {
|
||||
title: 'NAY2Y Smoke Test',
|
||||
sku: 'SMOKE-TEST-001',
|
||||
slug: 'nay2y',
|
||||
description: 'A dummy product for CI/CD smoke testing and OG image verification.',
|
||||
locale: 'de',
|
||||
categories: [{ category: 'Power Cables' }],
|
||||
_status: 'published',
|
||||
},
|
||||
});
|
||||
payload.logger.info('✅ Smoke test product created successfully.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user