const db = require('../models'); const Users = db.users; const Accounts = db.accounts; const Announcements = db.announcements; const BarterOffers = db.barter_offers; const DelayedPayments = db.delayed_payments; const IslamicFinanceLibrary = db.islamic_finance_library; const LoanApplications = db.loan_applications; const Partners = db.partners; const Projects = db.projects; const Transactions = db.transactions; const Kooperatif = db.kooperatif; const AccountsData = [ { // type code here for "relation_one" field balance: 10000, debt_limit: 5000, current_debt: 2000, account_type: 'TL', // type code here for "relation_one" field }, { // type code here for "relation_one" field balance: 15000, debt_limit: 7000, current_debt: 3000, account_type: 'KatılımEmeklilikHesabı', // type code here for "relation_one" field }, { // type code here for "relation_one" field balance: 20000, debt_limit: 10000, current_debt: 5000, account_type: 'ALTIN', // type code here for "relation_one" field }, ]; const AnnouncementsData = [ { title: 'Annual General Meeting', content: 'The annual general meeting will be held on March 15th.', published_date: new Date('2023-02-01T00:00:00Z'), // type code here for "relation_one" field }, { title: 'New Partnership', content: 'We are pleased to announce a new partnership with XYZ Corp.', published_date: new Date('2023-02-10T00:00:00Z'), // type code here for "relation_one" field }, { title: 'Holiday Closure', content: 'The office will be closed for the national holiday on April 23rd.', published_date: new Date('2023-03-20T00:00:00Z'), // type code here for "relation_one" field }, ]; const BarterOffersData = [ { // type code here for "relation_one" field offer_details: 'Offering agricultural products for construction materials.', offer_date: new Date('2023-08-15T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field offer_details: 'Retail goods in exchange for financial services.', offer_date: new Date('2023-09-15T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field offer_details: 'Construction services for educational resources.', offer_date: new Date('2023-10-15T00:00:00Z'), // type code here for "relation_one" field }, ]; const DelayedPaymentsData = [ { // type code here for "relation_one" field amount: 1000, due_date: new Date('2023-07-01T00:00:00Z'), notified: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 2000, due_date: new Date('2023-07-05T00:00:00Z'), notified: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 1500, due_date: new Date('2023-07-10T00:00:00Z'), notified: true, // type code here for "relation_one" field }, ]; const IslamicFinanceLibraryData = [ { title: 'Introduction to Islamic Finance', content: 'An overview of the principles of Islamic finance.', resource_type: 'Resource', // type code here for "relation_one" field }, { title: 'Islamic Banking Models', content: 'Different models of Islamic banking and their applications.', resource_type: 'Resource', // type code here for "relation_one" field }, { title: 'Shariah Compliance in Finance', content: 'Ensuring financial products comply with Shariah law.', resource_type: 'Article', // type code here for "relation_one" field }, ]; const LoanApplicationsData = [ { // type code here for "relation_one" field amount: 3000, loan_type: 'KrediliAlışVeriş', application_date: new Date('2023-06-01T00:00:00Z'), approved: true, // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 5000, loan_type: 'KrediliAlışVeriş', application_date: new Date('2023-06-10T00:00:00Z'), approved: false, // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 7000, loan_type: 'YatırımGiderleri', application_date: new Date('2023-06-15T00:00:00Z'), approved: true, // type code here for "relation_one" field }, ]; const PartnersData = [ { name: 'Ali Veli', tc_number: '12345678901', tax_number: '9876543210', insurance_number: '123456789', phone: '5551234567', sector: 'Agriculture', registration_date: new Date('2023-01-15T00:00:00Z'), // type code here for "relation_one" field }, { name: 'Ayşe Yılmaz', tc_number: '23456789012', tax_number: '8765432109', insurance_number: '234567890', phone: '5552345678', sector: 'Retail', registration_date: new Date('2023-02-20T00:00:00Z'), // type code here for "relation_one" field }, { name: 'Mehmet Kaya', tc_number: '34567890123', tax_number: '7654321098', insurance_number: '345678901', phone: '5553456789', sector: 'Construction', registration_date: new Date('2023-03-10T00:00:00Z'), // type code here for "relation_one" field }, ]; const ProjectsData = [ { // type code here for "relation_one" field title: 'Green Energy Initiative', description: 'A project to develop sustainable energy solutions.', start_date: new Date('2023-08-01T00:00:00Z'), end_date: new Date('2023-12-01T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field title: 'Retail Expansion', description: 'Expanding retail operations to new regions.', start_date: new Date('2023-09-01T00:00:00Z'), end_date: new Date('2024-01-01T00:00:00Z'), // type code here for "relation_one" field }, { // type code here for "relation_one" field title: 'Construction Innovation', description: 'Innovative construction techniques for urban development.', start_date: new Date('2023-10-01T00:00:00Z'), end_date: new Date('2024-02-01T00:00:00Z'), // type code here for "relation_one" field }, ]; const TransactionsData = [ { // type code here for "relation_one" field amount: 500, transaction_date: new Date('2023-07-01T00:00:00Z'), transaction_type: 'Deposit', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 1000, transaction_date: new Date('2023-07-05T00:00:00Z'), transaction_type: 'Payment', // type code here for "relation_one" field }, { // type code here for "relation_one" field amount: 1500, transaction_date: new Date('2023-07-10T00:00:00Z'), transaction_type: 'Withdrawal', // type code here for "relation_one" field }, ]; const KooperatifData = [ { name: 'Francis Crick', }, { name: 'Max Planck', }, { name: 'Richard Feynman', }, ]; // Similar logic for "relation_many" async function associateUserWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const User0 = await Users.findOne({ order: [['id', 'ASC']], offset: 0, }); if (User0?.setKooperatif) { await User0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const User1 = await Users.findOne({ order: [['id', 'ASC']], offset: 1, }); if (User1?.setKooperatif) { await User1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const User2 = await Users.findOne({ order: [['id', 'ASC']], offset: 2, }); if (User2?.setKooperatif) { await User2.setKooperatif(relatedKooperatif2); } } async function associateAccountWithPartner() { const relatedPartner0 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const Account0 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Account0?.setPartner) { await Account0.setPartner(relatedPartner0); } const relatedPartner1 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const Account1 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Account1?.setPartner) { await Account1.setPartner(relatedPartner1); } const relatedPartner2 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const Account2 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Account2?.setPartner) { await Account2.setPartner(relatedPartner2); } } async function associateAccountWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Account0 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Account0?.setKooperatif) { await Account0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Account1 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Account1?.setKooperatif) { await Account1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Account2 = await Accounts.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Account2?.setKooperatif) { await Account2.setKooperatif(relatedKooperatif2); } } async function associateAnnouncementWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Announcement0 = await Announcements.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Announcement0?.setKooperatif) { await Announcement0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Announcement1 = await Announcements.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Announcement1?.setKooperatif) { await Announcement1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Announcement2 = await Announcements.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Announcement2?.setKooperatif) { await Announcement2.setKooperatif(relatedKooperatif2); } } async function associateBarterOfferWithPartner() { const relatedPartner0 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const BarterOffer0 = await BarterOffers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (BarterOffer0?.setPartner) { await BarterOffer0.setPartner(relatedPartner0); } const relatedPartner1 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const BarterOffer1 = await BarterOffers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (BarterOffer1?.setPartner) { await BarterOffer1.setPartner(relatedPartner1); } const relatedPartner2 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const BarterOffer2 = await BarterOffers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (BarterOffer2?.setPartner) { await BarterOffer2.setPartner(relatedPartner2); } } async function associateBarterOfferWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const BarterOffer0 = await BarterOffers.findOne({ order: [['id', 'ASC']], offset: 0, }); if (BarterOffer0?.setKooperatif) { await BarterOffer0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const BarterOffer1 = await BarterOffers.findOne({ order: [['id', 'ASC']], offset: 1, }); if (BarterOffer1?.setKooperatif) { await BarterOffer1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const BarterOffer2 = await BarterOffers.findOne({ order: [['id', 'ASC']], offset: 2, }); if (BarterOffer2?.setKooperatif) { await BarterOffer2.setKooperatif(relatedKooperatif2); } } async function associateDelayedPaymentWithPartner() { const relatedPartner0 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const DelayedPayment0 = await DelayedPayments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (DelayedPayment0?.setPartner) { await DelayedPayment0.setPartner(relatedPartner0); } const relatedPartner1 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const DelayedPayment1 = await DelayedPayments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (DelayedPayment1?.setPartner) { await DelayedPayment1.setPartner(relatedPartner1); } const relatedPartner2 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const DelayedPayment2 = await DelayedPayments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (DelayedPayment2?.setPartner) { await DelayedPayment2.setPartner(relatedPartner2); } } async function associateDelayedPaymentWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const DelayedPayment0 = await DelayedPayments.findOne({ order: [['id', 'ASC']], offset: 0, }); if (DelayedPayment0?.setKooperatif) { await DelayedPayment0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const DelayedPayment1 = await DelayedPayments.findOne({ order: [['id', 'ASC']], offset: 1, }); if (DelayedPayment1?.setKooperatif) { await DelayedPayment1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const DelayedPayment2 = await DelayedPayments.findOne({ order: [['id', 'ASC']], offset: 2, }); if (DelayedPayment2?.setKooperatif) { await DelayedPayment2.setKooperatif(relatedKooperatif2); } } async function associateIslamicFinanceLibraryWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const IslamicFinanceLibrary0 = await IslamicFinanceLibrary.findOne({ order: [['id', 'ASC']], offset: 0, }); if (IslamicFinanceLibrary0?.setKooperatif) { await IslamicFinanceLibrary0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const IslamicFinanceLibrary1 = await IslamicFinanceLibrary.findOne({ order: [['id', 'ASC']], offset: 1, }); if (IslamicFinanceLibrary1?.setKooperatif) { await IslamicFinanceLibrary1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const IslamicFinanceLibrary2 = await IslamicFinanceLibrary.findOne({ order: [['id', 'ASC']], offset: 2, }); if (IslamicFinanceLibrary2?.setKooperatif) { await IslamicFinanceLibrary2.setKooperatif(relatedKooperatif2); } } async function associateLoanApplicationWithPartner() { const relatedPartner0 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const LoanApplication0 = await LoanApplications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (LoanApplication0?.setPartner) { await LoanApplication0.setPartner(relatedPartner0); } const relatedPartner1 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const LoanApplication1 = await LoanApplications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (LoanApplication1?.setPartner) { await LoanApplication1.setPartner(relatedPartner1); } const relatedPartner2 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const LoanApplication2 = await LoanApplications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (LoanApplication2?.setPartner) { await LoanApplication2.setPartner(relatedPartner2); } } async function associateLoanApplicationWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const LoanApplication0 = await LoanApplications.findOne({ order: [['id', 'ASC']], offset: 0, }); if (LoanApplication0?.setKooperatif) { await LoanApplication0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const LoanApplication1 = await LoanApplications.findOne({ order: [['id', 'ASC']], offset: 1, }); if (LoanApplication1?.setKooperatif) { await LoanApplication1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const LoanApplication2 = await LoanApplications.findOne({ order: [['id', 'ASC']], offset: 2, }); if (LoanApplication2?.setKooperatif) { await LoanApplication2.setKooperatif(relatedKooperatif2); } } async function associatePartnerWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Partner0 = await Partners.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Partner0?.setKooperatif) { await Partner0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Partner1 = await Partners.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Partner1?.setKooperatif) { await Partner1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Partner2 = await Partners.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Partner2?.setKooperatif) { await Partner2.setKooperatif(relatedKooperatif2); } } async function associateProjectWithPartner() { const relatedPartner0 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setPartner) { await Project0.setPartner(relatedPartner0); } const relatedPartner1 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setPartner) { await Project1.setPartner(relatedPartner1); } const relatedPartner2 = await Partners.findOne({ offset: Math.floor(Math.random() * (await Partners.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setPartner) { await Project2.setPartner(relatedPartner2); } } async function associateProjectWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Project0 = await Projects.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Project0?.setKooperatif) { await Project0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Project1 = await Projects.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Project1?.setKooperatif) { await Project1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Project2 = await Projects.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Project2?.setKooperatif) { await Project2.setKooperatif(relatedKooperatif2); } } async function associateTransactionWithAccount() { const relatedAccount0 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Transaction0 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Transaction0?.setAccount) { await Transaction0.setAccount(relatedAccount0); } const relatedAccount1 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Transaction1 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Transaction1?.setAccount) { await Transaction1.setAccount(relatedAccount1); } const relatedAccount2 = await Accounts.findOne({ offset: Math.floor(Math.random() * (await Accounts.count())), }); const Transaction2 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Transaction2?.setAccount) { await Transaction2.setAccount(relatedAccount2); } } async function associateTransactionWithKooperatif() { const relatedKooperatif0 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Transaction0 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 0, }); if (Transaction0?.setKooperatif) { await Transaction0.setKooperatif(relatedKooperatif0); } const relatedKooperatif1 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Transaction1 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 1, }); if (Transaction1?.setKooperatif) { await Transaction1.setKooperatif(relatedKooperatif1); } const relatedKooperatif2 = await Kooperatif.findOne({ offset: Math.floor(Math.random() * (await Kooperatif.count())), }); const Transaction2 = await Transactions.findOne({ order: [['id', 'ASC']], offset: 2, }); if (Transaction2?.setKooperatif) { await Transaction2.setKooperatif(relatedKooperatif2); } } module.exports = { up: async (queryInterface, Sequelize) => { await Accounts.bulkCreate(AccountsData); await Announcements.bulkCreate(AnnouncementsData); await BarterOffers.bulkCreate(BarterOffersData); await DelayedPayments.bulkCreate(DelayedPaymentsData); await IslamicFinanceLibrary.bulkCreate(IslamicFinanceLibraryData); await LoanApplications.bulkCreate(LoanApplicationsData); await Partners.bulkCreate(PartnersData); await Projects.bulkCreate(ProjectsData); await Transactions.bulkCreate(TransactionsData); await Kooperatif.bulkCreate(KooperatifData); await Promise.all([ // Similar logic for "relation_many" await associateUserWithKooperatif(), await associateAccountWithPartner(), await associateAccountWithKooperatif(), await associateAnnouncementWithKooperatif(), await associateBarterOfferWithPartner(), await associateBarterOfferWithKooperatif(), await associateDelayedPaymentWithPartner(), await associateDelayedPaymentWithKooperatif(), await associateIslamicFinanceLibraryWithKooperatif(), await associateLoanApplicationWithPartner(), await associateLoanApplicationWithKooperatif(), await associatePartnerWithKooperatif(), await associateProjectWithPartner(), await associateProjectWithKooperatif(), await associateTransactionWithAccount(), await associateTransactionWithKooperatif(), ]); }, down: async (queryInterface, Sequelize) => { await queryInterface.bulkDelete('accounts', null, {}); await queryInterface.bulkDelete('announcements', null, {}); await queryInterface.bulkDelete('barter_offers', null, {}); await queryInterface.bulkDelete('delayed_payments', null, {}); await queryInterface.bulkDelete('islamic_finance_library', null, {}); await queryInterface.bulkDelete('loan_applications', null, {}); await queryInterface.bulkDelete('partners', null, {}); await queryInterface.bulkDelete('projects', null, {}); await queryInterface.bulkDelete('transactions', null, {}); await queryInterface.bulkDelete('kooperatif', null, {}); }, };