Changeset 057453c for prisma/seed.js
- Timestamp:
- 02/26/25 10:05:32 (6 weeks ago)
- Branches:
- main
- Children:
- 299af01
- Parents:
- 5d6f37a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified prisma/seed.js ¶
r5d6f37a r057453c 4 4 5 5 async function main() { 6 console.log('🌱 Seeding database...'); 6 // Clear existing data 7 await prisma.service.deleteMany(); 8 await prisma.tenant.deleteMany(); 7 9 8 // Create Customers 9 const customer1 = await prisma.customer.create({ 10 data: { 11 name: 'Acme Corp', 12 email: 'contact@acme.com', 13 street: '123 Main St', 14 city: 'New York', 15 country: 'USA', 16 state: 'NY', 17 zip: '10001', 18 phoneNumber: '+1 555-555-5555', 19 vatNumber: 'US123456789', 20 companyNumber: '123456789', 21 representative: 'John Doe', 22 status: 'ACTIVE', 23 logoUrl: 'https://example.com/logo.png', 10 // Define default tenant data 11 const tenantData = { 12 name: "Default Company", 13 email: "contact@defaultcompany.com", 14 address: { 15 street: "123 Business Street", 16 city: "Business City", 17 state: "BS", 18 zip: "12345", 19 country: "United States" 24 20 }, 21 phoneNumber: "+1 234 567 8900", 22 representative: "John Doe", 23 lastInvoiceNumber: "1", 24 logoUrl: "https://example.com/default-logo.png", 25 vatNumber: "VAT123456789", 26 companyNumber: "COMP123456", 27 bankAccounts: { 28 eur: { 29 accountNumber: "1234567890", 30 routingNumber: "987654321", 31 bicSwift: "DEFBANKXXX", 32 iban: "DE89370400440532013000" 33 }, 34 usd: { 35 accountNumber: "0987654321", 36 routingNumber: "123456789", 37 bicSwift: "DEFBANKXXX", 38 iban: "US89370400440532013000" 39 } 40 }, 41 // Add services along with the tenant creation 42 services: { 43 create: [ 44 { 45 name: "Web Development", 46 sprint: 5000, 47 hour: 150, 48 month: 8000 49 }, 50 { 51 name: "UI/UX Design", 52 sprint: 3000, 53 hour: 120, 54 month: 6000 55 }, 56 { 57 name: "Consulting", 58 sprint: 4000, 59 hour: 200, 60 month: 7000 61 } 62 ] 63 } 64 }; 65 66 // Create default tenant with services 67 const defaultTenant = await prisma.tenant.create({ 68 data: tenantData, 69 include: { 70 services: true 71 } 25 72 }); 26 73 27 const customer2 = await prisma.customer.create({ 28 data: { 29 name: 'Globex Ltd.', 30 email: 'info@globex.com', 31 street: '456 Industrial Rd', 32 city: 'Los Angeles', 33 country: 'USA', 34 state: 'CA', 35 zip: '90001', 36 phoneNumber: '+1 555-123-4567', 37 vatNumber: 'US987654321', 38 companyNumber: '987654321', 39 representative: 'Jane Smith', 40 status: 'INACTIVE', 41 logoUrl: 'https://example.com/logo2.png', 42 }, 43 }); 74 console.log('Seeded default tenant:', defaultTenant); 44 75 45 // Create Bank Accounts 46 await prisma.bankAccount.createMany({ 47 data: [ 48 { 49 customerId: customer1.id, 50 accountNumber: '1234567890', 51 bicSwift: 'ACMEUS33', 52 iban: 'US12345678901234567890', 53 routingNumber: '111000025', 54 currency: 'USD', 55 }, 56 { 57 customerId: customer2.id, 58 accountNumber: '0987654321', 59 bicSwift: 'GLOBEXUS12', 60 iban: 'US09876543210987654321', 61 routingNumber: '222000033', 62 currency: 'EUR', 63 }, 64 ], 65 }); 66 67 // Create Services 68 const service1 = await prisma.service.create({ 69 data: { 70 name: 'Web Development', 71 sprintPrice: 5000.0, 72 hourPrice: 100.0, 73 monthPrice: 20000.0, 74 }, 75 }); 76 77 const service2 = await prisma.service.create({ 78 data: { 79 name: 'SEO Optimization', 80 sprintPrice: 3000.0, 81 hourPrice: 75.0, 82 monthPrice: 12000.0, 83 }, 84 }); 85 86 // Create Invoices 87 const invoice1 = await prisma.invoice.create({ 88 data: { 89 dueDate: new Date('2025-03-15'), 90 status: 'PENDING', 91 currency: 'USD', 92 quantityType: 'HOUR', 93 subTotal: 5000.0, 94 createDate: new Date(), 95 month: 'FEBRUARY', 96 discount: 0.0, 97 taxes: 500.0, 98 totalAmount: 5500.0, 99 invoiceNumber: 'INV-2025-001', 100 pdfRef: 'https://example.com/invoice1.pdf', 101 invoiceFromId: customer1.id, 102 invoiceToId: customer2.id, 103 }, 104 }); 105 106 // Create Invoice Items 107 await prisma.invoiceItem.create({ 108 data: { 109 title: 'Web Development - Sprint 1', 110 price: 5000.0, 111 total: 5000.0, 112 quantity: 1, 113 description: 'Development of the MVP frontend', 114 serviceId: service1.id, 115 invoiceId: invoice1.id, 116 }, 117 }); 76 console.log('🌱 Seeding database...'); 118 77 119 78 console.log('✅ Seeding complete!'); … … 122 81 main() 123 82 .catch((e) => { 124 console.error( e);83 console.error('Error seeding database:', e); 125 84 process.exit(1); 126 85 })
Note:
See TracChangeset
for help on using the changeset viewer.