diff --git a/Dockerfile b/Dockerfile
index e1284e5..a512250 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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/package.json ./package.json
COPY --from=builder --chown=remix:nodejs /app/prisma ./prisma
+COPY --from=builder --chown=remix:nodejs /app/scripts ./scripts
# Copy production dependencies
COPY --from=deps --chown=remix:nodejs /app/node_modules ./node_modules
@@ -60,10 +61,24 @@ set -e
echo "Starting Phosphat Report Application..."
-# Run database migrations and seed
-echo "Running database setup..."
+# Run database migrations
+echo "Running database migrations..."
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..."
exec npm start
diff --git a/app/routes/dashboard.tsx b/app/routes/dashboard.tsx
index e650849..2ea790c 100644
--- a/app/routes/dashboard.tsx
+++ b/app/routes/dashboard.tsx
@@ -162,7 +162,7 @@ export default function Dashboard() {
- {new Date(report.createdDate).toLocaleDateString()}
+ {new Date(report.createdDate).toLocaleDateString('en-GB')}
diff --git a/package.json b/package.json
index 75cf44f..d9c4083 100644
--- a/package.json
+++ b/package.json
@@ -52,6 +52,6 @@
"node": ">=20.0.0"
},
"prisma": {
- "seed": "tsx prisma/seed.ts"
+ "seed": "node prisma/seed.js"
}
}
diff --git a/prisma/seed.js b/prisma/seed.js
new file mode 100644
index 0000000..0252645
--- /dev/null
+++ b/prisma/seed.js
@@ -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();
+ });
\ No newline at end of file
diff --git a/scripts/seed-production.js b/scripts/seed-production.js
new file mode 100644
index 0000000..38ca7ad
--- /dev/null
+++ b/scripts/seed-production.js
@@ -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);
+ });
\ No newline at end of file