upload 2 3

This commit is contained in:
yznahmad 2025-07-24 14:03:05 +03:00
parent 0df60ac516
commit 4ec910ed1f
5 changed files with 313 additions and 5 deletions

View File

@ -45,6 +45,7 @@ COPY --from=builder --chown=remix:nodejs /app/build ./build
COPY --from=builder --chown=remix:nodejs /app/public ./public COPY --from=builder --chown=remix:nodejs /app/public ./public
COPY --from=builder --chown=remix:nodejs /app/package.json ./package.json COPY --from=builder --chown=remix:nodejs /app/package.json ./package.json
COPY --from=builder --chown=remix:nodejs /app/prisma ./prisma COPY --from=builder --chown=remix:nodejs /app/prisma ./prisma
COPY --from=builder --chown=remix:nodejs /app/scripts ./scripts
# Copy production dependencies # Copy production dependencies
COPY --from=deps --chown=remix:nodejs /app/node_modules ./node_modules COPY --from=deps --chown=remix:nodejs /app/node_modules ./node_modules
@ -60,10 +61,24 @@ set -e
echo "Starting Phosphat Report Application..." echo "Starting Phosphat Report Application..."
# Run database migrations and seed # Run database migrations
echo "Running database setup..." echo "Running database migrations..."
npx prisma db push --accept-data-loss npx prisma db push --accept-data-loss
npx prisma db seed
# Run seed using production script
echo "Seeding database..."
if [ -f "scripts/seed-production.js" ]; then
echo "Using production seed script..."
node scripts/seed-production.js
else
echo "Production seed script not found, trying alternative methods..."
if [ -f "prisma/seed.js" ]; then
echo "Using JavaScript seed file..."
node prisma/seed.js
else
echo "No seeding method available, skipping..."
fi
fi
echo "Database setup complete. Starting application..." echo "Database setup complete. Starting application..."
exec npm start exec npm start

View File

@ -162,7 +162,7 @@ export default function Dashboard() {
</div> </div>
</div> </div>
<div className="text-sm text-gray-500"> <div className="text-sm text-gray-500">
{new Date(report.createdDate).toLocaleDateString()} {new Date(report.createdDate).toLocaleDateString('en-GB')}
</div> </div>
</div> </div>
</div> </div>

View File

@ -52,6 +52,6 @@
"node": ">=20.0.0" "node": ">=20.0.0"
}, },
"prisma": { "prisma": {
"seed": "tsx prisma/seed.ts" "seed": "node prisma/seed.js"
} }
} }

147
prisma/seed.js Normal file
View File

@ -0,0 +1,147 @@
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient();
async function main() {
console.log('🌱 Seeding database...');
// Seed Areas
const areas = await Promise.all([
prisma.area.upsert({
where: { name: 'Petra' },
update: {},
create: { name: 'Petra' }
}),
prisma.area.upsert({
where: { name: 'Jarash' },
update: {},
create: { name: 'Jarash' }
}),
prisma.area.upsert({
where: { name: 'Rum' },
update: {},
create: { name: 'Rum' }
})
]);
// Seed DredgerLocations
const dredgerLocations = await Promise.all([
prisma.dredgerLocation.upsert({
where: { name: 'SP1-1' },
update: {},
create: { name: 'SP1-1', class: 'SP' }
}),
prisma.dredgerLocation.upsert({
where: { name: 'SP1-2' },
update: {},
create: { name: 'SP1-2', class: 'SP' }
}),
prisma.dredgerLocation.upsert({
where: { name: 'C01' },
update: {},
create: { name: 'C01', class: 'C' }
}),
prisma.dredgerLocation.upsert({
where: { name: 'D1' },
update: {},
create: { name: 'D1', class: 'D' }
})
]);
// Seed ReclamationLocations
const reclamationLocations = await Promise.all([
prisma.reclamationLocation.upsert({
where: { name: 'Eastern Shoreline' },
update: {},
create: { name: 'Eastern Shoreline' }
}),
prisma.reclamationLocation.upsert({
where: { name: 'Western Shoreline' },
update: {},
create: { name: 'Western Shoreline' }
})
]);
// Seed Super Admin Employee
const superAdminUsername = process.env.SUPER_ADMIN || 'superadmin';
const superAdminEmail = process.env.SUPER_ADMIN_EMAIL || 'admin@example.com';
const superAdminPassword = process.env.SUPER_ADMIN_PASSWORD || 'P@ssw0rd123';
await prisma.employee.upsert({
where: { username: superAdminUsername },
update: {},
create: {
name: 'Super Admin User',
authLevel: 3,
username: superAdminUsername,
email: superAdminEmail,
password: bcrypt.hashSync(superAdminPassword, 10)
}
});
// Seed Foreman
await prisma.foreman.upsert({
where: { id: 1 },
update: {},
create: {
name: 'John Smith'
}
});
// Seed Equipment
const equipment = await Promise.all([
prisma.equipment.upsert({
where: { id: 1 },
update: {},
create: { id: 1, category: 'Dozer', model: 'Dozer6', number: 1 }
}),
prisma.equipment.upsert({
where: { id: 2 },
update: {},
create: { id: 2, category: 'Dozer', model: 'Dozer6', number: 2 }
}),
prisma.equipment.upsert({
where: { id: 3 },
update: {},
create: { id: 3, category: 'Dozer', model: 'Dozer7', number: 1 }
}),
prisma.equipment.upsert({
where: { id: 4 },
update: {},
create: { id: 4, category: 'Dozer', model: 'Dozer8', number: 1 }
}),
prisma.equipment.upsert({
where: { id: 5 },
update: {},
create: { id: 5, category: 'Loader', model: 'Loader', number: 1 }
}),
prisma.equipment.upsert({
where: { id: 6 },
update: {},
create: { id: 6, category: 'Excavator', model: 'Exc.', number: 1 }
}),
prisma.equipment.upsert({
where: { id: 7 },
update: {},
create: { id: 7, category: 'Excavator', model: 'Exc.', number: 9 }
})
]);
console.log('✅ Database seeded successfully!');
console.log(`Created ${areas.length} areas`);
console.log(`Created ${dredgerLocations.length} dredger locations`);
console.log(`Created ${reclamationLocations.length} reclamation locations`);
console.log(`Created 1 employee`);
console.log(`Created 1 foreman`);
console.log(`Created ${equipment.length} equipment records`);
}
main()
.catch((e) => {
console.error('❌ Error seeding database:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});

146
scripts/seed-production.js Normal file
View File

@ -0,0 +1,146 @@
#!/usr/bin/env node
// Production seed script that doesn't require tsx or other dev dependencies
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient();
async function seedDatabase() {
try {
console.log('🌱 Starting database seeding...');
// Check if database is already seeded
const existingAdmin = await prisma.employee.findFirst({
where: { authLevel: 3 }
});
if (existingAdmin) {
console.log('✅ Database already seeded, skipping...');
return;
}
// Seed Areas
console.log('📍 Seeding areas...');
const areas = [
{ name: 'Petra' },
{ name: 'Jarash' },
{ name: 'Rum' }
];
for (const area of areas) {
await prisma.area.upsert({
where: { name: area.name },
update: {},
create: area
});
}
// Seed DredgerLocations
console.log('🚢 Seeding dredger locations...');
const dredgerLocations = [
{ name: 'SP1-1', class: 'SP' },
{ name: 'SP1-2', class: 'SP' },
{ name: 'C01', class: 'C' },
{ name: 'D1', class: 'D' }
];
for (const location of dredgerLocations) {
await prisma.dredgerLocation.upsert({
where: { name: location.name },
update: {},
create: location
});
}
// Seed ReclamationLocations
console.log('🏖️ Seeding reclamation locations...');
const reclamationLocations = [
{ name: 'Eastern Shoreline' },
{ name: 'Western Shoreline' }
];
for (const location of reclamationLocations) {
await prisma.reclamationLocation.upsert({
where: { name: location.name },
update: {},
create: location
});
}
// Seed Super Admin Employee
console.log('👤 Creating super admin user...');
const superAdminUsername = process.env.SUPER_ADMIN || 'superadmin';
const superAdminEmail = process.env.SUPER_ADMIN_EMAIL || 'admin@example.com';
const superAdminPassword = process.env.SUPER_ADMIN_PASSWORD || 'P@ssw0rd123';
await prisma.employee.upsert({
where: { username: superAdminUsername },
update: {},
create: {
name: 'Super Admin User',
authLevel: 3,
username: superAdminUsername,
email: superAdminEmail,
password: bcrypt.hashSync(superAdminPassword, 10)
}
});
// Seed Foreman
console.log('👷 Seeding foreman...');
await prisma.foreman.upsert({
where: { id: 1 },
update: {},
create: {
id: 1,
name: 'John Smith'
}
});
// Seed Equipment
console.log('🚜 Seeding equipment...');
const equipment = [
{ id: 1, category: 'Dozer', model: 'Dozer6', number: 1 },
{ id: 2, category: 'Dozer', model: 'Dozer6', number: 2 },
{ id: 3, category: 'Dozer', model: 'Dozer7', number: 1 },
{ id: 4, category: 'Dozer', model: 'Dozer8', number: 1 },
{ id: 5, category: 'Loader', model: 'Loader', number: 1 },
{ id: 6, category: 'Excavator', model: 'Exc.', number: 1 },
{ id: 7, category: 'Excavator', model: 'Exc.', number: 9 }
];
for (const item of equipment) {
await prisma.equipment.upsert({
where: { id: item.id },
update: {},
create: item
});
}
console.log('✅ Database seeded successfully!');
console.log(`📊 Summary:`);
console.log(` - ${areas.length} areas`);
console.log(` - ${dredgerLocations.length} dredger locations`);
console.log(` - ${reclamationLocations.length} reclamation locations`);
console.log(` - 1 super admin user`);
console.log(` - 1 foreman`);
console.log(` - ${equipment.length} equipment records`);
} catch (error) {
console.error('❌ Error seeding database:', error);
throw error;
} finally {
await prisma.$disconnect();
}
}
// Run the seeding
seedDatabase()
.then(() => {
console.log('🎉 Seeding completed successfully!');
process.exit(0);
})
.catch((error) => {
console.error('💥 Seeding failed:', error);
process.exit(1);
});