- Timestamp:
- 02/26/25 10:05:32 (6 weeks ago)
- Branches:
- main
- Children:
- 299af01
- Parents:
- 5d6f37a
- Location:
- prisma
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
prisma/schema.prisma
r5d6f37a r057453c 8 8 } 9 9 10 model C ustomer{10 model Client { 11 11 id String @id @default(uuid()) 12 12 companyId String? // Optional company identifier … … 21 21 status CustomerStatus @default(active) 22 22 23 bankAccounts BankAccount[] // One-to-many relation24 invoicesSent Invoice[] @relation("InvoiceFrom")25 23 invoicesReceived Invoice[] @relation("InvoiceTo") 26 }27 28 model BankAccount {29 id String @id @default(uuid())30 customerId String31 customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)32 accountNumber String?33 bicSwift String?34 iban String?35 routingNumber String?36 currency Currency37 24 } 38 25 … … 40 27 id String @id @default(uuid()) 41 28 name String 42 sprintPrice Float 43 hourPrice Float 44 monthPrice Float 29 sprint Float 30 hour Float 31 month Float 32 tenantId String 33 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade) 45 34 46 invoiceItems InvoiceItem[]35 lineItems LineItem[] 47 36 } 48 37 … … 64 53 65 54 invoiceFromId String 66 invoiceFrom Customer @relation("InvoiceFrom",fields: [invoiceFromId], references: [id], onDelete: Cascade)55 invoiceFrom Tenant @relation(fields: [invoiceFromId], references: [id], onDelete: Cascade) 67 56 68 57 invoiceToId String 69 invoiceTo C ustomer@relation("InvoiceTo", fields: [invoiceToId], references: [id], onDelete: Cascade)58 invoiceTo Client @relation("InvoiceTo", fields: [invoiceToId], references: [id], onDelete: Cascade) 70 59 71 items InvoiceItem[]60 items LineItem[] 72 61 } 73 62 74 model InvoiceItem {63 model LineItem { 75 64 id String @id @default(uuid()) 76 65 title String … … 85 74 } 86 75 76 model Tenant { 77 id String @id @default(cuid()) 78 name String 79 email String @unique 80 address Json // Holds {street: string, city?: string, country: string, state?: string, zip: string} 81 bankAccounts Json? // Holds {eur?: {accountNumber?, bicSwift?, iban?, routingNumber?}, usd?: {...}} 82 logoUrl String? 83 phoneNumber String? 84 vatNumber String? 85 companyNumber String? 86 representative String 87 lastInvoiceNumber String @default("0") 88 createdAt DateTime @default(now()) 89 updatedAt DateTime @updatedAt 90 invoicesSent Invoice[] 91 services Service[] 92 employees Employee[] 93 } 94 95 model Employee { 96 id String @id @default(uuid()) 97 name String 98 email String @unique 99 status EmployeeStatus @default(active) 100 iban String? 101 cv String? 102 photo String? 103 project String? 104 tenantId String 105 tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade) 106 } 107 87 108 // Enums 88 109 enum CustomerStatus { … … 93 114 94 115 enum InvoiceStatus { 95 DRAFT96 PROCESSING97 PENDING98 OVERDUE99 PAID116 draft 117 processing 118 pending 119 overdue 120 paid 100 121 } 101 122 … … 106 127 107 128 enum QuantityType { 108 U NIT109 H OUR110 S PRINT111 M ONTH129 Unit 130 Hour 131 Sprint 132 Month 112 133 } 113 134 114 135 enum Month { 115 J ANUARY116 F EBRUARY117 M ARCH118 A PRIL119 M AY120 J UNE121 J ULY122 A UGUST123 S EPTEMBER124 O CTOBER125 N OVEMBER126 D ECEMBER136 January 137 February 138 March 139 April 140 May 141 June 142 July 143 August 144 September 145 October 146 November 147 December 127 148 } 149 150 enum EmployeeStatus { 151 active 152 inactive 153 } -
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.