procbay-schema 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/package.json +77 -0
- package/prisma/.env +13 -0
- package/prisma/migrations/20250116142512_init_user_table/migration.sql +38 -0
- package/prisma/migrations/20250116142709_init_role_table/migration.sql +20 -0
- package/prisma/migrations/20250116143847_init_user_role_table/migration.sql +20 -0
- package/prisma/migrations/20250116144035_init_permission_table/migration.sql +21 -0
- package/prisma/migrations/20250116144140_init_role_permission_table/migration.sql +21 -0
- package/prisma/migrations/20250116144233_init_department_table/migration.sql +20 -0
- package/prisma/migrations/20250116144345_init_user_department_table/migration.sql +20 -0
- package/prisma/migrations/20250116152941_init_serial_number_table/migration.sql +17 -0
- package/prisma/migrations/20250116153048_init_category_table/migration.sql +22 -0
- package/prisma/migrations/20250116153415_init_attributes_table/migration.sql +28 -0
- package/prisma/migrations/20250116153628_init_attribute_values_table/migration.sql +27 -0
- package/prisma/migrations/20250116153900_init_purchase_intake_table/migration.sql +32 -0
- package/prisma/migrations/20250116154038_init_purchase_intake_item_table/migration.sql +15 -0
- package/prisma/migrations/20250120090355_added_reset_token_column_in_user_table/migration.sql +10 -0
- package/prisma/migrations/20250120100616_init_item_table/migration.sql +42 -0
- package/prisma/migrations/20250120123720_init_vendor_table/migration.sql +39 -0
- package/prisma/migrations/20250120124526_init_vendor_categories_table/migration.sql +20 -0
- package/prisma/migrations/20250122114935_added_email_template_and_smtp_config_table/migration.sql +41 -0
- package/prisma/migrations/20250123095637_chnages_in_vendr_table/migration.sql +3 -0
- package/prisma/migrations/20250123103705_added_delated_filed_in_email_template_table/migration.sql +4 -0
- package/prisma/migrations/20250123103810_added_delated_filed_in_smtp_config_table/migration.sql +13 -0
- package/prisma/migrations/20250127123900_create_approval_heirarchy_table/migration.sql +72 -0
- package/prisma/migrations/20250128054523_make_optional_role_and_user_in_approval_hierachy/migration.sql +3 -0
- package/prisma/migrations/20250129084223_item_table_chnages/migration.sql +151 -0
- package/prisma/migrations/20250130115331_chnages_in_item_table/migration.sql +9 -0
- package/prisma/migrations/20250131054132_added_approval_journey_table/migration.sql +22 -0
- package/prisma/migrations/20250131064653_added_default_for_product_id_in_item_table/migration.sql +2 -0
- package/prisma/migrations/20250204101253_chnages_in_approval_table/migration.sql +39 -0
- package/prisma/migrations/20250206091422_added_item_document_table/migration.sql +17 -0
- package/prisma/migrations/20250207113110_added_new_column_media/migration.sql +9 -0
- package/prisma/migrations/20250207125224_added_chnages_in_pr_table/migration.sql +12 -0
- package/prisma/migrations/20250212092048_vendor_contact_table/migration.sql +30 -0
- package/prisma/migrations/20250212133620_added_tamplate_master_table/migration.sql +43 -0
- package/prisma/migrations/20250213111908_created_faq_catgory_and_faq_table/migration.sql +58 -0
- package/prisma/migrations/20250214065142_chnages_in_uom_table/migration.sql +50 -0
- package/prisma/migrations/20250217061122_corrected_email_teamplate_table/migration.sql +11 -0
- package/prisma/migrations/20250218073530_init_events/migration.sql +120 -0
- package/prisma/migrations/20250218092119_corrected_table_name/migration.sql +37 -0
- package/prisma/migrations/20250218120935_chnages_in_event_table/migration.sql +5 -0
- package/prisma/migrations/20250219083326_added_new_table_for_event_startegy/migration.sql +60 -0
- package/prisma/migrations/20250219083416_added_cms_table/migration.sql +29 -0
- package/prisma/migrations/20250219092918_alter_event_table/migration.sql +5 -0
- package/prisma/migrations/20250219093046_alter_event_to_draft/migration.sql +2 -0
- package/prisma/migrations/20250220080337_altered_event_table/migration.sql +9 -0
- package/prisma/migrations/20250221105922_added_unique_to_email_in_user_table/migration.sql +8 -0
- package/prisma/migrations/20250225063838_created_vendor_kyc_table/migration.sql +23 -0
- package/prisma/migrations/20250227060646_template_field_types_added_enum/migration.sql +14 -0
- package/prisma/migrations/20250227110306_updated_event_items_and_event_vendor_table/migration.sql +7 -0
- package/prisma/migrations/20250228060440_added_country_code_in_vendor_contact_person/migration.sql +2 -0
- package/prisma/migrations/20250228095319_init_currencies_table/migration.sql +23 -0
- package/prisma/migrations/20250303082614_added_support_ticket_table/migration.sql +89 -0
- package/prisma/migrations/20250304050248_alter_support_ticket_relations/migration.sql +35 -0
- package/prisma/migrations/20250304050613_alter_support_ticket_realtions/migration.sql +36 -0
- package/prisma/migrations/20250304061954_init_support_category_table/migration.sql +261 -0
- package/prisma/migrations/20250304092346_alter_event_vendor_table/migration.sql +2 -0
- package/prisma/migrations/20250305065430_alter_vendor_kyc_table/migration.sql +2 -0
- package/prisma/migrations/20250305111735_alter_vendor_and_user_table/migration.sql +5 -0
- package/prisma/migrations/20250307033751_alter_token_version_in_user_and_vendor_token/migration.sql +5 -0
- package/prisma/migrations/20250307034907_alter_user_and_vendor_table/migration.sql +14 -0
- package/prisma/migrations/20250307064359_chnages_in_approval_herarcy_table/migration.sql +2 -0
- package/prisma/migrations/20250307105352_alter_itme_and_vendorkyc_table/migration.sql +21 -0
- package/prisma/migrations/20250310103914_init_vendor_status_table/migration.sql +21 -0
- package/prisma/migrations/20250310105209_alter_vendor_status_table/migration.sql +18 -0
- package/prisma/migrations/20250310105413_init_vendor_kyc_status_table/migration.sql +23 -0
- package/prisma/migrations/20250311090552_alter_vendor_kyc_status_table/migration.sql +2 -0
- package/prisma/migrations/20250312055258_alter_status_column_in_event_vendors/migration.sql +12 -0
- package/prisma/migrations/20250312072145_init_vendor_event_watchlist_table/migration.sql +26 -0
- package/prisma/migrations/20250312083842_alter_vendor_event_watchlisst_table/migration.sql +41 -0
- package/prisma/migrations/20250312134730_added_chnages_in_kyc_table/migration.sql +19 -0
- package/prisma/migrations/20250317040841_init_admin_and_vendor_tables/migration.sql +38 -0
- package/prisma/migrations/20250317044110_alter_event_vendor_table/migration.sql +2 -0
- package/prisma/migrations/20250317071807_alter_rejected_reason_in_approval_journey_and_purchase_intak_table/migration.sql +5 -0
- package/prisma/migrations/20250318085504_init_customer_notification_table/migration.sql +31 -0
- package/prisma/migrations/20250318085856_alter_purchase_intake_table/migration.sql +18 -0
- package/prisma/migrations/20250319085159_alter_purchase_intake_table/migration.sql +12 -0
- package/prisma/migrations/20250320093356_init_bid_and_bidlog_table/migration.sql +75 -0
- package/prisma/migrations/20250320095501_alter_email_template_table/migration.sql +2 -0
- package/prisma/migrations/20250321053926_alter_approval_journey_table/migration.sql +2 -0
- package/prisma/migrations/20250324040851_alter_bidlog_table/migration.sql +2 -0
- package/prisma/migrations/20250324091328_init_form_master_and_dynamic_form_table/migration.sql +53 -0
- package/prisma/migrations/20250324103742_alter_bidlog_table/migration.sql +5 -0
- package/prisma/migrations/20250325052714_alter_form_master_table/migration.sql +27 -0
- package/prisma/migrations/20250327011625_init_module_and_tenant_configuration_table/migration.sql +39 -0
- package/prisma/migrations/20250403054008_alter_purchase_intake_table/migration.sql +5 -0
- package/prisma/migrations/20250404115613_init_approval_level_user/migration.sql +98 -0
- package/prisma/migrations/20250410060521_alter_approval_journey_enums/migration.sql +12 -0
- package/prisma/migrations/20250410110823_alter_purchase_intake/migration.sql +2 -0
- package/prisma/migrations/20250411062955_alter_template_field_table/migration.sql +2 -0
- package/prisma/migrations/20250414065640_alter_template/migration.sql +2 -0
- package/prisma/migrations/20250414111856_alter_event_vendors/migration.sql +2 -0
- package/prisma/migrations/20250414125356_alter_event_vendor/migration.sql +9 -0
- package/prisma/migrations/20250415063558_alter_alert_type_enum/migration.sql +2 -0
- package/prisma/migrations/20250416062508_alter_purchase_intake_table/migration.sql +15 -0
- package/prisma/migrations/20250417090325_alter_purchase_intake_table_updated_enum/migration.sql +13 -0
- package/prisma/migrations/20250417111024_alter_purchase_intake_and_purchase_intake_item/migration.sql +16 -0
- package/prisma/migrations/20250421061732_init_quotation_and_quotation_log_tables/migration.sql +96 -0
- package/prisma/migrations/20250421112331_alter_item_table_added_unique_to_slug/migration.sql +8 -0
- package/prisma/migrations/20250422060655_init_user_activity_table/migration.sql +17 -0
- package/prisma/migrations/20250423053027_/migration.sql +9 -0
- package/prisma/migrations/20250423103233_alter_user_login_activity_table/migration.sql +5 -0
- package/prisma/migrations/20250423111141_init_location_tables/migration.sql +141 -0
- package/prisma/migrations/20250424120106_alter_event_table_added_user_relation/migration.sql +2 -0
- package/prisma/migrations/20250424141637_alter_states_table/migration.sql +11 -0
- package/prisma/migrations/20250425105131_alter_user_login_activity_table/migration.sql +9 -0
- package/prisma/migrations/20250428092626_alter_location_tables/migration.sql +34 -0
- package/prisma/migrations/20250428114301_alter_location_table/migration.sql +14 -0
- package/prisma/migrations/20250429103436_alter_event_vendor_table/migration.sql +14 -0
- package/prisma/migrations/20250429135621_alter_event_vendor_table/migration.sql +5 -0
- package/prisma/migrations/20250430094809_alter_form_master_table_added_user_relation/migration.sql +2 -0
- package/prisma/migrations/20250430103440_alter_event_table/migration.sql +3 -0
- package/prisma/migrations/20250501125411_alter_strategies_table/migration.sql +2 -0
- package/prisma/migrations/20250502065554_init_location_table/migration.sql +41 -0
- package/prisma/migrations/20250505104038_alter_bid_quotation_and_dynamic_form/migration.sql +22 -0
- package/prisma/migrations/20250505105253_alter_quotation/migration.sql +5 -0
- package/prisma/migrations/20250505124851_alter_alert_enum/migration.sql +56 -0
- package/prisma/migrations/20250505133250_init_sub_module_table/migration.sql +17 -0
- package/prisma/migrations/20250506054325_alter_event_vendor_bid_status/migration.sql +14 -0
- package/prisma/migrations/20250506102135_init_counter_offer_table/migration.sql +38 -0
- package/prisma/migrations/20250506103355_alter_bid_and_quotaion_table/migration.sql +5 -0
- package/prisma/migrations/20250506110309_alter_tenant_configuration_table/migration.sql +3 -0
- package/prisma/migrations/20250506123527_alter_vendor_kyu_infor_verification_status/migration.sql +2 -0
- package/prisma/migrations/20250507055536_alter_dynamic_form_table/migration.sql +2 -0
- package/prisma/migrations/20250507070518_alter_bid_log_and_quotation_log/migration.sql +15 -0
- package/prisma/migrations/20250507130834_alter_bid_status/migration.sql +10 -0
- package/prisma/migrations/20250508065503_alter_purchase_intake_item_table/migration.sql +16 -0
- package/prisma/migrations/20250508130119_alter_purchase_intake_item/migration.sql +13 -0
- package/prisma/migrations/20250512082244_altered_template_table_to_add_currency_id/migration.sql +12 -0
- package/prisma/migrations/20250512100817_alter_approval_journey_table/migration.sql +3 -0
- package/prisma/migrations/20250513083700_alter_item_table/migration.sql +2 -0
- package/prisma/migrations/20250514100915_alter_event_table_added_template_realtion/migration.sql +2 -0
- package/prisma/migrations/20250514103503_alter_vendor_table_added_is_kyc_approved_column/migration.sql +2 -0
- package/prisma/migrations/20250520131556_init_purchase_order_table/migration.sql +52 -0
- package/prisma/migrations/20250521113946_alter_purchase_order_status_enum/migration.sql +16 -0
- package/prisma/migrations/20250522083917_alter_event_vendor_bid_status_enum/migration.sql +17 -0
- package/prisma/migrations/20250522131610_updated_vendor_table/migration.sql +16 -0
- package/prisma/migrations/20250523051058_alter_vendor_kyc_verificaiton_status_enum/migration.sql +2 -0
- package/prisma/migrations/20250526072120_alter_vendor_table/migration.sql +16 -0
- package/prisma/migrations/20250527055351_init_purchase_order_activity_log/migration.sql +41 -0
- package/prisma/migrations/20250528060657_alter_item_tale/migration.sql +14 -0
- package/prisma/migrations/20250528061946_alter_event_item_table/migration.sql +5 -0
- package/prisma/migrations/20250528081337_alter_item_table/migration.sql +2 -0
- package/prisma/migrations/20250528081524_removed_item_id_from_item_table/migration.sql +11 -0
- package/prisma/migrations/20250528081843_alter_item_table/migration.sql +2 -0
- package/prisma/migrations/20250528094057_alter_alert_type_enum/migration.sql +11 -0
- package/prisma/migrations/20250529053721_alter_added_quantity_in_purchase_order/migration.sql +2 -0
- package/prisma/migrations/20250602055114_alter_approval_journey_parent_id_to_string/migration.sql +2 -0
- package/prisma/migrations/20250602055748_alter_event_configuration_added_rule_slug/migration.sql +2 -0
- package/prisma/migrations/20250602111042_init_user_vendor_socket_token_table/migration.sql +17 -0
- package/prisma/migrations/20250602125833_alter_bidlog_and_quoatationlog_tableto_add_json_field/migration.sql +5 -0
- package/prisma/migrations/20250603063501_alter_bid_and_quoatation_table/migration.sql +29 -0
- package/prisma/migrations/20250606015045_alter_quotation_log_table/migration.sql +2 -0
- package/prisma/migrations/20250606020918_alter_quotation_table/migration.sql +2 -0
- package/prisma/migrations/20250606022901_alter_quotation_log_table/migration.sql +3 -0
- package/prisma/migrations/20250606054914_init_event_activity_logs_table/migration.sql +35 -0
- package/prisma/migrations/20250606100634_alter_added_counter_offer_status/migration.sql +5 -0
- package/prisma/migrations/20250606100908_alter_counter_offer_table/migration.sql +2 -0
- package/prisma/migrations/20250610055710_alter_enum/migration.sql +16 -0
- package/prisma/migrations/20250610060558_alter_event_and_event_vendor_db/migration.sql +14 -0
- package/prisma/migrations/20250610091013_alter_purchase_intak_item_table/migration.sql +4 -0
- package/prisma/migrations/20250610100156_alter_purchase_intake_item_table/migration.sql +19 -0
- package/prisma/migrations/20250610125706_alter_event_table/migration.sql +6 -0
- package/prisma/migrations/20250610133613_added_timestamp/migration.sql +319 -0
- package/prisma/migrations/20250611090439_init_contact_us_table/migration.sql +23 -0
- package/prisma/migrations/20250611121005_alter_event_vendor_table/migration.sql +10 -0
- package/prisma/migrations/20250612064335_alter_tenant_configuration/migration.sql +3 -0
- package/prisma/migrations/20250612094643_alter_event_vendor_bid_status_enum/migration.sql +2 -0
- package/prisma/migrations/20250618074558_alter_updated_bid_status_and_quotation_status/migration.sql +21 -0
- package/prisma/migrations/20250618122242_alter_added_event_phase_closed/migration.sql +2 -0
- package/prisma/migrations/20250620054518_alter_event_phase/migration.sql +2 -0
- package/prisma/migrations/20250620062723_alter_event_phase/migration.sql +2 -0
- package/prisma/migrations/20250620063056_alter_event_phase/migration.sql +2 -0
- package/prisma/migrations/20250620100507_alter_event_phase/migration.sql +2 -0
- package/prisma/migrations/20250627104958_alter_counter_offer_status/migration.sql +2 -0
- package/prisma/migrations/20250702095923_alter_item_table/migration.sql +74 -0
- package/prisma/migrations/20250702120134_/migration.sql +14 -0
- package/prisma/migrations/20250702150717_alter_attribute_table/migration.sql +9 -0
- package/prisma/migrations/20250703090321_alter_item_table/migration.sql +2 -0
- package/prisma/migrations/20250707054625_alter_purchase_order_table/migration.sql +15 -0
- package/prisma/migrations/20250707111354_alter_purchase_order_table_and_init_purchase_order_item_table/migration.sql +39 -0
- package/prisma/migrations/20250707111522_alter_purchase_order_item_table/migration.sql +17 -0
- package/prisma/migrations/20250710054113_alter_bid_and_quotation_status/migration.sql +31 -0
- package/prisma/migrations/20250710070813_alter_event_status/migration.sql +2 -0
- package/prisma/migrations/20250710082332_alter_bid_and_quotations_table/migration.sql +36 -0
- package/prisma/migrations/20250714102325_init_upload_log_table/migration.sql +27 -0
- package/prisma/migrations/20250716061012_alter_event_activity_logs_to_activity_logs/migration.sql +48 -0
- package/prisma/migrations/20250716071839_init_chat_thread_chat_message_and_ai_models/migration.sql +56 -0
- package/prisma/migrations/20250716135548_alter_admin_alerts_enum/migration.sql +2 -0
- package/prisma/migrations/20250717100515_init_user_event_configuration/migration.sql +21 -0
- package/prisma/migrations/20250717101037_alter_user_event_configuration_table/migration.sql +19 -0
- package/prisma/migrations/20250718071630_alter_added_module_in_upload_logs_table/migration.sql +5 -0
- package/prisma/migrations/20250718071732_alter_module_enum/migration.sql +15 -0
- package/prisma/migrations/20250721054851_init_export_log_table/migration.sql +34 -0
- package/prisma/migrations/20250722054549_init_fiscal_year_table/migration.sql +22 -0
- package/prisma/migrations/20250722072051_alter_fiscal_year_table_added_uuid/migration.sql +14 -0
- package/prisma/migrations/20250722095259_alter_fiscal_table/migration.sql +9 -0
- package/prisma/migrations/20250723071050_alter_department_table/migration.sql +14 -0
- package/prisma/migrations/20250724071201_alter_export_upload_log_enum/migration.sql +8 -0
- package/prisma/migrations/20250725094759_new_migrate/migration.sql +2 -0
- package/prisma/migrations/20250725095012_alter_migration/migration.sql +2 -0
- package/prisma/migrations/20250728072402_init_budget_management_tables/migration.sql +80 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +2609 -0
- package/prisma/seeders/approval-hierarchy.seed.js +340 -0
- package/prisma/seeders/attribute-value.seed.js +64 -0
- package/prisma/seeders/attribute.seed.js +61 -0
- package/prisma/seeders/category.seed.js +133 -0
- package/prisma/seeders/city.seed.js +147 -0
- package/prisma/seeders/country.seed.js +282 -0
- package/prisma/seeders/currency.seed.js +41 -0
- package/prisma/seeders/customer-notification.seed.js +83 -0
- package/prisma/seeders/department.seed.js +38 -0
- package/prisma/seeders/docs/CORE_SEEDER_OPTIMIZATIONS.md +270 -0
- package/prisma/seeders/docs/GEOGRAPHIC_PERFORMANCE_OPTIMIZATIONS.md +175 -0
- package/prisma/seeders/dynamic-form.seed.js +135 -0
- package/prisma/seeders/email-template.seed.js +68 -0
- package/prisma/seeders/faq-category.seed.js +56 -0
- package/prisma/seeders/faq.seed.js +61 -0
- package/prisma/seeders/form-master.seed.js +55 -0
- package/prisma/seeders/item.seed.js +133 -0
- package/prisma/seeders/permission.seed.js +102 -0
- package/prisma/seeders/region.seed.js +78 -0
- package/prisma/seeders/role-permission.seed.js +70 -0
- package/prisma/seeders/role.seed.js +38 -0
- package/prisma/seeders/seed.js +553 -0
- package/prisma/seeders/serial-number-config.seed.js +58 -0
- package/prisma/seeders/smtp-config.seed.js +61 -0
- package/prisma/seeders/state.seed.js +170 -0
- package/prisma/seeders/strategies.seed.js +54 -0
- package/prisma/seeders/subregion.seed.js +88 -0
- package/prisma/seeders/support-category.seed.js +56 -0
- package/prisma/seeders/template.seed.js +87 -0
- package/prisma/seeders/test-core-seeders.js +276 -0
- package/prisma/seeders/user-department.seed.js +66 -0
- package/prisma/seeders/user-event-configuration.seed.js +47 -0
- package/prisma/seeders/user-role.seed.js +74 -0
- package/prisma/seeders/user.seed.js +114 -0
- package/prisma/seeders/utils/bulk-seeder.js +300 -0
- package/prisma/seeders/utils/config.js +103 -0
- package/prisma/seeders/utils/connection-manager.js +380 -0
- package/prisma/seeders/utils/content-seeder.js +472 -0
- package/prisma/seeders/utils/core-seeder.js +330 -0
- package/prisma/seeders/utils/json-loader.js +69 -0
- package/prisma/seeders/utils/performance-config.js +341 -0
- package/prisma/seeders/utils/performance-helpers.js +206 -0
- package/prisma/seeders/utils/progress-tracker.js +364 -0
- package/prisma/seeders/utils/seeder-config-mapper.js +316 -0
- package/scripts/seed-databases.js +873 -0
- package/scripts/sync-schemas.js +865 -0
- package/scripts/truncate-tables.js +1048 -0
- package/src/prisma/client.d.ts +1 -0
- package/src/prisma/client.js +4 -0
- package/src/prisma/default.d.ts +1 -0
- package/src/prisma/default.js +4 -0
- package/src/prisma/edge.d.ts +1 -0
- package/src/prisma/edge.js +2084 -0
- package/src/prisma/index-browser.js +2043 -0
- package/src/prisma/index.d.ts +202051 -0
- package/src/prisma/index.js +2113 -0
- package/src/prisma/libquery_engine-darwin.dylib.node +0 -0
- package/src/prisma/libquery_engine-darwin.dylib.node.tmp24628 +0 -0
- package/src/prisma/libquery_engine-darwin.dylib.node.tmp29464 +0 -0
- package/src/prisma/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
- package/src/prisma/package.json +140 -0
- package/src/prisma/query_engine-windows.dll.node +0 -0
- package/src/prisma/query_engine-windows.dll.node.tmp4144 +0 -0
- package/src/prisma/runtime/edge-esm.js +34 -0
- package/src/prisma/runtime/edge.js +34 -0
- package/src/prisma/runtime/index-browser.d.ts +370 -0
- package/src/prisma/runtime/index-browser.js +16 -0
- package/src/prisma/runtime/library.d.ts +3647 -0
- package/src/prisma/runtime/library.js +146 -0
- package/src/prisma/runtime/react-native.js +83 -0
- package/src/prisma/runtime/wasm.js +35 -0
- package/src/prisma/schema.prisma +2609 -0
- package/src/prisma/wasm.d.ts +1 -0
- package/src/prisma/wasm.js +2043 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import colors from "colors";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { PrismaClient } from "../../src/prisma/index.js";
|
|
4
|
+
import { seedUsers } from "./user.seed.js";
|
|
5
|
+
import { seedRoles } from "./role.seed.js";
|
|
6
|
+
import { seedPermissions } from "./permission.seed.js";
|
|
7
|
+
import { seedDepartments } from "./department.seed.js";
|
|
8
|
+
import { seedCurrencies } from "./currency.seed.js";
|
|
9
|
+
import { seedRolePermission } from "./role-permission.seed.js";
|
|
10
|
+
import { seedUserRole } from "./user-role.seed.js";
|
|
11
|
+
import { seedSerialNumberConfigurations } from "./serial-number-config.seed.js";
|
|
12
|
+
import { seedTemplates } from "./template.seed.js";
|
|
13
|
+
import { seedEmailTemplate } from "./email-template.seed.js";
|
|
14
|
+
import { seedUserEventConfigurations } from "./user-event-configuration.seed.js";
|
|
15
|
+
// Import geo data seeders
|
|
16
|
+
import { seedRegions } from "./region.seed.js";
|
|
17
|
+
import { seedSubregions } from "./subregion.seed.js";
|
|
18
|
+
import { seedCountries } from "./country.seed.js";
|
|
19
|
+
import { seedStates } from "./state.seed.js";
|
|
20
|
+
import { seedCities } from "./city.seed.js";
|
|
21
|
+
import { seedDynamicForm } from "./dynamic-form.seed.js";
|
|
22
|
+
// Import optimization utilities
|
|
23
|
+
import { createPerformanceConfig, PERFORMANCE_PRESETS } from "./utils/performance-config.js";
|
|
24
|
+
import { getConnectionManager } from "./utils/connection-manager.js";
|
|
25
|
+
import { createSeederManager, determineDataVolume } from "./utils/seeder-config-mapper.js";
|
|
26
|
+
|
|
27
|
+
// Initialize colors
|
|
28
|
+
colors.setTheme({
|
|
29
|
+
info: "blue",
|
|
30
|
+
success: "green",
|
|
31
|
+
warn: "yellow",
|
|
32
|
+
error: "red",
|
|
33
|
+
highlight: "cyan",
|
|
34
|
+
muted: "gray",
|
|
35
|
+
header: ["bold", "cyan"],
|
|
36
|
+
progress: "magenta",
|
|
37
|
+
bold: "bold",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Create logger function with timing and colors
|
|
41
|
+
const createLogger = () => {
|
|
42
|
+
const startTime = Date.now();
|
|
43
|
+
const formatTime = () => {
|
|
44
|
+
const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
45
|
+
return colors.muted(`[${elapsed}s]`);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Check if detailed logging is enabled
|
|
49
|
+
const isDetailedLogging = process.env.DETAILED_LOGGING === "true";
|
|
50
|
+
|
|
51
|
+
// Get log level from environment or default to info
|
|
52
|
+
const LOG_LEVELS = {
|
|
53
|
+
debug: 0,
|
|
54
|
+
info: 1,
|
|
55
|
+
warn: 2,
|
|
56
|
+
error: 3,
|
|
57
|
+
silent: 4,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const currentLogLevel = LOG_LEVELS[process.env.LOG_LEVEL || "info"];
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
info: (message) => {
|
|
64
|
+
// Always log info messages when detailed logging is enabled
|
|
65
|
+
if (isDetailedLogging || currentLogLevel <= LOG_LEVELS.info) {
|
|
66
|
+
console.log(`${formatTime()} ${colors.info("ℹ️")} ${message}`);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
success: (message) => {
|
|
70
|
+
// Always log success messages when detailed logging is enabled
|
|
71
|
+
if (isDetailedLogging || currentLogLevel <= LOG_LEVELS.info) {
|
|
72
|
+
console.log(
|
|
73
|
+
`${formatTime()} ${colors.success("✅")} ${colors.success(message)}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
warn: (message) => {
|
|
78
|
+
// Always log warning messages when detailed logging is enabled
|
|
79
|
+
if (isDetailedLogging || currentLogLevel <= LOG_LEVELS.warn) {
|
|
80
|
+
console.warn(
|
|
81
|
+
`${formatTime()} ${colors.warn("⚠️")} ${colors.warn(message)}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
error: (message) => {
|
|
86
|
+
// Always log error messages
|
|
87
|
+
console.error(
|
|
88
|
+
`${formatTime()} ${colors.error("❌")} ${colors.error(message)}`
|
|
89
|
+
);
|
|
90
|
+
},
|
|
91
|
+
header: (message) => {
|
|
92
|
+
// Always log header messages when detailed logging is enabled
|
|
93
|
+
if (isDetailedLogging || currentLogLevel <= LOG_LEVELS.info) {
|
|
94
|
+
console.log(
|
|
95
|
+
`\n${colors.header(message)}\n${colors.muted("━".repeat(80))}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
progressStart: (total, message) => {
|
|
100
|
+
const progress = { current: 0, total, message };
|
|
101
|
+
progress.update = (increment = 1) => {
|
|
102
|
+
progress.current += increment;
|
|
103
|
+
const percent = Math.min(
|
|
104
|
+
Math.floor((progress.current / total) * 100),
|
|
105
|
+
100
|
|
106
|
+
);
|
|
107
|
+
const filled = Math.floor((40 * progress.current) / total);
|
|
108
|
+
const bar =
|
|
109
|
+
colors.progress("█".repeat(filled)) +
|
|
110
|
+
colors.muted("░".repeat(40 - filled));
|
|
111
|
+
|
|
112
|
+
// Only write progress if detailed logging is enabled or at appropriate log level
|
|
113
|
+
if (isDetailedLogging || currentLogLevel <= LOG_LEVELS.info) {
|
|
114
|
+
process.stdout.write(
|
|
115
|
+
`\r${formatTime()} ${colors.highlight(
|
|
116
|
+
message
|
|
117
|
+
)}: ${bar} ${colors.bold(`${percent}%`)} (${
|
|
118
|
+
progress.current
|
|
119
|
+
}/${total})`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
progress.complete = () => {
|
|
124
|
+
if (progress.current < total) {
|
|
125
|
+
progress.current = total;
|
|
126
|
+
progress.update(0); // Just redraw without incrementing
|
|
127
|
+
}
|
|
128
|
+
if (isDetailedLogging || currentLogLevel <= LOG_LEVELS.info) {
|
|
129
|
+
process.stdout.write("\n");
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
return progress;
|
|
133
|
+
},
|
|
134
|
+
progressBar: (current, total, message = "") => {
|
|
135
|
+
const percent = Math.min(Math.floor((current / total) * 100), 100);
|
|
136
|
+
const filled = Math.floor((40 * current) / total);
|
|
137
|
+
const bar =
|
|
138
|
+
colors.progress("█".repeat(filled)) +
|
|
139
|
+
colors.muted("░".repeat(40 - filled));
|
|
140
|
+
return `${bar} ${colors.bold(`${percent}%`)} ${
|
|
141
|
+
message ? `(${message})` : ""
|
|
142
|
+
}`;
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const logger = createLogger();
|
|
148
|
+
|
|
149
|
+
const prisma = new PrismaClient({
|
|
150
|
+
log: [
|
|
151
|
+
{ level: "query", emit: "event" },
|
|
152
|
+
{ level: "error", emit: "stdout" },
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Count executed queries for monitoring
|
|
157
|
+
let queryCount = 0;
|
|
158
|
+
prisma.$on("query", () => {
|
|
159
|
+
queryCount++;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Parse command line arguments for country filters
|
|
164
|
+
*
|
|
165
|
+
* Example usage:
|
|
166
|
+
* node prisma/seeders/seed.js --countries="India,United States,Canada"
|
|
167
|
+
*
|
|
168
|
+
* @returns {Object} Object containing parsed arguments
|
|
169
|
+
*/
|
|
170
|
+
function parseArgs() {
|
|
171
|
+
const args = {};
|
|
172
|
+
|
|
173
|
+
// Get command line arguments
|
|
174
|
+
const cmdArgs = process.argv.slice(2);
|
|
175
|
+
|
|
176
|
+
for (const arg of cmdArgs) {
|
|
177
|
+
if (arg.startsWith("--countries=")) {
|
|
178
|
+
const countryString = arg.split("=")[1];
|
|
179
|
+
args.countries = countryString.split(",").map((c) => c.trim());
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return args;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Main function to run all seeders
|
|
189
|
+
*
|
|
190
|
+
* @param {string[]} [countryFilter] - Optional array of country names to filter geographic data
|
|
191
|
+
*/
|
|
192
|
+
export async function main(countryFilter = ["India", "United States", "Canada"]) {
|
|
193
|
+
let connectionManager;
|
|
194
|
+
let seederManager;
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
// Initialize seeder manager with auto-config selection
|
|
198
|
+
const environment = process.env.NODE_ENV || 'development';
|
|
199
|
+
|
|
200
|
+
seederManager = createSeederManager({
|
|
201
|
+
environment,
|
|
202
|
+
countryFilter,
|
|
203
|
+
expectedRecords: countryFilter.length === 0 ? 100000 : countryFilter.length * 10000,
|
|
204
|
+
availableMemory: process.memoryUsage().free
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Log configuration summary
|
|
208
|
+
seederManager.logConfigSummary();
|
|
209
|
+
|
|
210
|
+
// Initialize connection manager
|
|
211
|
+
connectionManager = getConnectionManager({
|
|
212
|
+
connectionLimit: seederManager.performanceConfig.config.geographic.cities.connectionPoolSize,
|
|
213
|
+
idleTimeout: 300000,
|
|
214
|
+
acquireTimeout: 60000
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Print start message with environment info to help with debugging
|
|
218
|
+
console.log("\n================= SEED PROCESS STARTED =================");
|
|
219
|
+
console.log(`Node version: ${process.version}`);
|
|
220
|
+
console.log(`Environment: ${environment}`);
|
|
221
|
+
console.log(`Memory usage: ${JSON.stringify(process.memoryUsage())}`);
|
|
222
|
+
console.log(
|
|
223
|
+
`Database URL: ${
|
|
224
|
+
process.env.DEFAULT_DATABASE_URL ? "Defined" : "Not defined"
|
|
225
|
+
}`
|
|
226
|
+
);
|
|
227
|
+
console.log("=======================================================\n");
|
|
228
|
+
|
|
229
|
+
// If no countryFilter is provided, check command line args
|
|
230
|
+
if (!countryFilter || countryFilter.length === 0) {
|
|
231
|
+
const args = parseArgs();
|
|
232
|
+
countryFilter = args.countries || [];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
logger.header("🌱 DATABASE SEEDING PROCESS");
|
|
236
|
+
|
|
237
|
+
if (countryFilter.length > 0) {
|
|
238
|
+
logger.info(`Country filter applied: ${countryFilter.join(", ")}`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const startTime = Date.now();
|
|
242
|
+
|
|
243
|
+
// Run each seeding operation with detailed tracing
|
|
244
|
+
logger.info("Starting geographic data seeding...");
|
|
245
|
+
try {
|
|
246
|
+
// Run the geographic data seeding with connection retries
|
|
247
|
+
await seedGeographicDataWithRetry(countryFilter);
|
|
248
|
+
logger.success("Geographic data seeded successfully");
|
|
249
|
+
} catch (error) {
|
|
250
|
+
logger.error(`Geographic data seeding failed: ${error.message}`);
|
|
251
|
+
throw new Error(
|
|
252
|
+
`Geographic data seeding failed: ${error.stack || error.message}`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Seed base/core data next
|
|
257
|
+
logger.info("Starting core data seeding...");
|
|
258
|
+
try {
|
|
259
|
+
await seedCoreDataWithRetry(seederManager);
|
|
260
|
+
logger.success("Core data seeded successfully");
|
|
261
|
+
} catch (error) {
|
|
262
|
+
logger.error(`Core data seeding failed: ${error.message}`);
|
|
263
|
+
throw new Error(
|
|
264
|
+
`Core data seeding failed: ${error.stack || error.message}`
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Seed catalog and content data
|
|
269
|
+
logger.info("Starting content data seeding...");
|
|
270
|
+
try {
|
|
271
|
+
await seedContentDataWithRetry();
|
|
272
|
+
logger.success("Content data seeded successfully");
|
|
273
|
+
} catch (error) {
|
|
274
|
+
logger.error(`Content data seeding failed: ${error.message}`);
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Content data seeding failed: ${error.stack || error.message}`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Log completion stats
|
|
281
|
+
const totalTime = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
282
|
+
logger.header("✅ SEEDING COMPLETED");
|
|
283
|
+
logger.success(
|
|
284
|
+
`Database seeded successfully in ${colors.bold(
|
|
285
|
+
totalTime + "s"
|
|
286
|
+
)} with ${colors.bold(queryCount.toString())} database queries`
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
logger.info("All categories seeded.");
|
|
290
|
+
|
|
291
|
+
return true;
|
|
292
|
+
} catch (error) {
|
|
293
|
+
// Enhanced error logging
|
|
294
|
+
logger.error(`Error during seeding process`);
|
|
295
|
+
logger.error(`Error message: ${error.message}`);
|
|
296
|
+
logger.error(`Stack trace: ${error.stack || "No stack trace available"}`);
|
|
297
|
+
|
|
298
|
+
// Log memory usage in case we're hitting resource limits
|
|
299
|
+
console.error(
|
|
300
|
+
"Memory usage at failure:",
|
|
301
|
+
JSON.stringify(process.memoryUsage())
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Seeds geographic data (regions, subregions, countries, states, cities)
|
|
310
|
+
*
|
|
311
|
+
* @param {string[]} [countryFilter] - Optional array of country names to filter by
|
|
312
|
+
*/
|
|
313
|
+
export async function seedGeographicData(countryFilter = []) {
|
|
314
|
+
logger.header("🌎 GEOGRAPHIC DATA SEEDING");
|
|
315
|
+
|
|
316
|
+
const filteringMode =
|
|
317
|
+
countryFilter.length > 0
|
|
318
|
+
? `filtering by ${countryFilter.length} countries`
|
|
319
|
+
: "seeding all countries";
|
|
320
|
+
|
|
321
|
+
logger.info(
|
|
322
|
+
`Starting geographic data seeding ${colors.highlight(
|
|
323
|
+
"(using transaction)"
|
|
324
|
+
)} - ${colors.highlight(filteringMode)}`
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
try {
|
|
328
|
+
await prisma.$transaction(
|
|
329
|
+
async (tx) => {
|
|
330
|
+
// Always seed all regions and subregions regardless of country filter
|
|
331
|
+
logger.info(`Seeding ${colors.highlight("regions")}...`);
|
|
332
|
+
const regionIdMap = await seedRegions(tx);
|
|
333
|
+
|
|
334
|
+
logger.info(`Seeding ${colors.highlight("subregions")}...`);
|
|
335
|
+
const subregionIdMap = await seedSubregions(tx, regionIdMap);
|
|
336
|
+
|
|
337
|
+
// Filter countries if specified
|
|
338
|
+
logger.info(
|
|
339
|
+
`Seeding ${colors.highlight("countries")}${
|
|
340
|
+
countryFilter.length > 0 ? " (filtered)" : ""
|
|
341
|
+
}...`
|
|
342
|
+
);
|
|
343
|
+
const countryIdMap = await seedCountries(
|
|
344
|
+
tx,
|
|
345
|
+
regionIdMap,
|
|
346
|
+
subregionIdMap,
|
|
347
|
+
countryFilter
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
// Create a Set of filtered country JSON IDs if filtering is applied
|
|
351
|
+
let filteredCountryIds = null;
|
|
352
|
+
if (countryFilter.length > 0) {
|
|
353
|
+
filteredCountryIds = new Set();
|
|
354
|
+
// Populate the Set with the JSON IDs of filtered countries
|
|
355
|
+
countryIdMap.forEach((dbId, jsonId) => {
|
|
356
|
+
if (filteredCountryIds) {
|
|
357
|
+
filteredCountryIds.add(jsonId);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
logger.info(
|
|
363
|
+
`Seeding ${colors.highlight("states")}${
|
|
364
|
+
filteredCountryIds ? " (filtered)" : ""
|
|
365
|
+
}...`
|
|
366
|
+
);
|
|
367
|
+
const stateIdMap = await seedStates(
|
|
368
|
+
tx,
|
|
369
|
+
countryIdMap,
|
|
370
|
+
filteredCountryIds
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
logger.info(
|
|
374
|
+
`Seeding ${colors.highlight("cities")}${
|
|
375
|
+
filteredCountryIds ? " (filtered)" : ""
|
|
376
|
+
}...`
|
|
377
|
+
);
|
|
378
|
+
await seedCities(tx, countryIdMap, stateIdMap, filteredCountryIds);
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
timeout: 600000, // 10 minute transaction timeout
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
logger.success(
|
|
386
|
+
`Geographic data seeding completed successfully ${
|
|
387
|
+
countryFilter.length > 0 ? "(filtered mode)" : ""
|
|
388
|
+
}`
|
|
389
|
+
);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
logger.error(`Error in geographic data seeding: ${error.message}`);
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Add retry wrappers for each seeding phase
|
|
397
|
+
async function seedGeographicDataWithRetry(countryFilter = [], maxRetries = 3) {
|
|
398
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
399
|
+
try {
|
|
400
|
+
logger.info(`Geographic data seeding attempt ${attempt}/${maxRetries}`);
|
|
401
|
+
await seedGeographicData(countryFilter);
|
|
402
|
+
return; // Success, exit the function
|
|
403
|
+
} catch (error) {
|
|
404
|
+
logger.warn(
|
|
405
|
+
`Geographic data seeding attempt ${attempt} failed: ${error.message}`
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
if (attempt < maxRetries) {
|
|
409
|
+
const delay = 2000 * attempt; // Increasing delay between retries
|
|
410
|
+
logger.info(`Retrying in ${delay / 1000} seconds...`);
|
|
411
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
412
|
+
} else {
|
|
413
|
+
throw error; // Last attempt failed, rethrow the error
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Seeds core data (users, roles, permissions, etc.)
|
|
421
|
+
*/
|
|
422
|
+
export async function seedCoreData(seederManager) {
|
|
423
|
+
logger.header("👤 CORE DATA SEEDING");
|
|
424
|
+
|
|
425
|
+
try {
|
|
426
|
+
// Create a progress tracker for core data
|
|
427
|
+
const coreDataItems = [
|
|
428
|
+
{
|
|
429
|
+
name: "Serial Number Configurations",
|
|
430
|
+
fn: (prisma, seederMgr) => seedSerialNumberConfigurations(prisma, seederMgr),
|
|
431
|
+
},
|
|
432
|
+
{ name: "Departments", fn: (prisma, seederMgr) => seedDepartments(prisma, seederMgr) },
|
|
433
|
+
{ name: "Currencies", fn: (prisma, seederMgr) => seedCurrencies(prisma, seederMgr) },
|
|
434
|
+
{ name: "Users", fn: (prisma, seederMgr) => seedUsers(prisma, seederMgr) },
|
|
435
|
+
{ name: "Roles", fn: (prisma, seederMgr) => seedRoles(prisma, seederMgr) },
|
|
436
|
+
{ name: "Permissions", fn: (prisma, seederMgr) => seedPermissions(prisma, seederMgr) },
|
|
437
|
+
{ name: "Role permissions", fn: (prisma, seederMgr) => seedRolePermission(prisma, seederMgr) },
|
|
438
|
+
{ name: "User roles", fn: (prisma, seederMgr) => seedUserRole(prisma, seederMgr) },
|
|
439
|
+
{ name: "User event configurations", fn: (prisma, seederMgr) => seedUserEventConfigurations(prisma, seederMgr) },
|
|
440
|
+
];
|
|
441
|
+
|
|
442
|
+
const progress = logger.progressStart(
|
|
443
|
+
coreDataItems.length,
|
|
444
|
+
"Core data seeding progress"
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
// Run core seeders in sequence
|
|
448
|
+
for (const item of coreDataItems) {
|
|
449
|
+
logger.info(`Seeding ${colors.highlight(item.name)}...`);
|
|
450
|
+
await item.fn(prisma, seederManager);
|
|
451
|
+
progress.update();
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
progress.complete();
|
|
455
|
+
logger.success("Core data seeding completed successfully");
|
|
456
|
+
} catch (error) {
|
|
457
|
+
logger.error(`Error in core data seeding: ${error.message}`);
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Add retry wrappers for each seeding phase
|
|
463
|
+
async function seedCoreDataWithRetry(seederManager, maxRetries = 3) {
|
|
464
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
465
|
+
try {
|
|
466
|
+
logger.info(`Core data seeding attempt ${attempt}/${maxRetries}`);
|
|
467
|
+
await seedCoreData(seederManager);
|
|
468
|
+
return; // Success, exit the function
|
|
469
|
+
} catch (error) {
|
|
470
|
+
logger.warn(
|
|
471
|
+
`Core data seeding attempt ${attempt} failed: ${error.message}`
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
if (attempt < maxRetries) {
|
|
475
|
+
const delay = 2000 * attempt; // Increasing delay between retries
|
|
476
|
+
logger.info(`Retrying in ${delay / 1000} seconds...`);
|
|
477
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
478
|
+
} else {
|
|
479
|
+
throw error; // Last attempt failed, rethrow the error
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Seeds content data (FAQs, categories, attributes, etc.)
|
|
487
|
+
*/
|
|
488
|
+
export async function seedContentData() {
|
|
489
|
+
logger.header("📋 CONTENT DATA SEEDING");
|
|
490
|
+
|
|
491
|
+
try {
|
|
492
|
+
// Create a progress tracker for content data
|
|
493
|
+
const contentDataItems = [
|
|
494
|
+
{ name: "Templates", fn: (prisma) => seedTemplates(prisma) },
|
|
495
|
+
{ name: "Email Templates", fn: (prisma) => seedEmailTemplate(prisma) },
|
|
496
|
+
{ name: "Dynamic Forms", fn: (prisma) => seedDynamicForm(prisma) },
|
|
497
|
+
];
|
|
498
|
+
|
|
499
|
+
const progress = logger.progressStart(
|
|
500
|
+
contentDataItems.length,
|
|
501
|
+
"Content data seeding progress"
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
// Run content seeders in sequence
|
|
505
|
+
for (const item of contentDataItems) {
|
|
506
|
+
logger.info(`Seeding ${colors.highlight(item.name)}...`);
|
|
507
|
+
await item.fn(prisma);
|
|
508
|
+
progress.update();
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
progress.complete();
|
|
512
|
+
logger.success("Content data seeding completed successfully");
|
|
513
|
+
} catch (error) {
|
|
514
|
+
logger.error(`Error in content data seeding: ${error.message}`);
|
|
515
|
+
throw error;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Add retry wrappers for each seeding phase
|
|
520
|
+
async function seedContentDataWithRetry(maxRetries = 3) {
|
|
521
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
522
|
+
try {
|
|
523
|
+
logger.info(`Content data seeding attempt ${attempt}/${maxRetries}`);
|
|
524
|
+
await seedContentData();
|
|
525
|
+
return; // Success, exit the function
|
|
526
|
+
} catch (error) {
|
|
527
|
+
logger.warn(
|
|
528
|
+
`Content data seeding attempt ${attempt} failed: ${error.message}`
|
|
529
|
+
);
|
|
530
|
+
|
|
531
|
+
if (attempt < maxRetries) {
|
|
532
|
+
const delay = 2000 * attempt; // Increasing delay between retries
|
|
533
|
+
logger.info(`Retrying in ${delay / 1000} seconds...`);
|
|
534
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
535
|
+
} else {
|
|
536
|
+
throw error; // Last attempt failed, rethrow the error
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// Only run main if this script was called directly
|
|
543
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
544
|
+
await main()
|
|
545
|
+
.catch((e) => {
|
|
546
|
+
console.error(e);
|
|
547
|
+
process.exit(1);
|
|
548
|
+
})
|
|
549
|
+
.finally(async () => {
|
|
550
|
+
// Clean up by disconnecting Prisma Client
|
|
551
|
+
await prisma.$disconnect();
|
|
552
|
+
});
|
|
553
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PrismaClient } from "../../src/prisma/index.js";
|
|
2
|
+
import { loadCoreData } from "./utils/json-loader.js";
|
|
3
|
+
import {
|
|
4
|
+
createProgressTracker,
|
|
5
|
+
logSeederStart,
|
|
6
|
+
logSeederComplete,
|
|
7
|
+
logEntityError,
|
|
8
|
+
} from "./utils/progress-tracker.js";
|
|
9
|
+
|
|
10
|
+
export async function seedSerialNumberConfigurations(prismaClient) {
|
|
11
|
+
// Use the passed client or create new one only if needed (for standalone testing)
|
|
12
|
+
const prisma = prismaClient || new PrismaClient();
|
|
13
|
+
|
|
14
|
+
logSeederStart("serial number configurations");
|
|
15
|
+
|
|
16
|
+
// Load serial-number configurations from JSON
|
|
17
|
+
const serialNumberData = loadCoreData("serial-number-config");
|
|
18
|
+
|
|
19
|
+
// Create progress tracker
|
|
20
|
+
const tracker = createProgressTracker(
|
|
21
|
+
serialNumberData.length,
|
|
22
|
+
"serial number configurations"
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
for (const serialConfig of serialNumberData) {
|
|
26
|
+
try {
|
|
27
|
+
await prisma.serialNumberConfiguration.upsert({
|
|
28
|
+
where: {
|
|
29
|
+
module: serialConfig.module,
|
|
30
|
+
},
|
|
31
|
+
update: {
|
|
32
|
+
alias: serialConfig.alias,
|
|
33
|
+
},
|
|
34
|
+
create: {
|
|
35
|
+
module: serialConfig.module,
|
|
36
|
+
alias: serialConfig.alias,
|
|
37
|
+
initial_number: serialConfig.initial_number,
|
|
38
|
+
current_number: serialConfig.current_number,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
// Log error but don't interrupt progress bar
|
|
43
|
+
logEntityError(
|
|
44
|
+
"serial number configuration",
|
|
45
|
+
serialConfig.module,
|
|
46
|
+
error.message
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
tracker.update();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
logSeederComplete("Serial number configurations");
|
|
53
|
+
|
|
54
|
+
// Only disconnect if we created our own client
|
|
55
|
+
if (!prismaClient) {
|
|
56
|
+
await prisma.$disconnect();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PrismaClient } from "../../src/prisma/index.js";
|
|
2
|
+
import { loadCoreData } from "./utils/json-loader.js";
|
|
3
|
+
import {
|
|
4
|
+
createProgressTracker,
|
|
5
|
+
logSeederStart,
|
|
6
|
+
logSeederComplete,
|
|
7
|
+
logEntityError,
|
|
8
|
+
} from "./utils/progress-tracker.js";
|
|
9
|
+
|
|
10
|
+
export async function seedSmtpConfig(prismaClient) {
|
|
11
|
+
// Use the passed client or create new one only if needed (for standalone testing)
|
|
12
|
+
const prisma = prismaClient || new PrismaClient();
|
|
13
|
+
|
|
14
|
+
logSeederStart("smtp config");
|
|
15
|
+
|
|
16
|
+
// Load SMTP configuration from JSON
|
|
17
|
+
const smtpConfigData = loadCoreData("smtp-config");
|
|
18
|
+
|
|
19
|
+
// Create progress tracker
|
|
20
|
+
const tracker = createProgressTracker(smtpConfigData.length, "smtp configs");
|
|
21
|
+
|
|
22
|
+
for (const smtpConfig of smtpConfigData) {
|
|
23
|
+
try {
|
|
24
|
+
await prisma.smtpConfig.upsert({
|
|
25
|
+
where: {
|
|
26
|
+
smtp_server: smtpConfig.smtp_server,
|
|
27
|
+
},
|
|
28
|
+
update: {
|
|
29
|
+
port: smtpConfig.port,
|
|
30
|
+
username: smtpConfig.username,
|
|
31
|
+
password: smtpConfig.password,
|
|
32
|
+
from_email: smtpConfig.from_email,
|
|
33
|
+
encryption: smtpConfig.encryption,
|
|
34
|
+
test_email: smtpConfig.test_email,
|
|
35
|
+
is_active: smtpConfig.is_active,
|
|
36
|
+
},
|
|
37
|
+
create: {
|
|
38
|
+
smtp_server: smtpConfig.smtp_server,
|
|
39
|
+
port: smtpConfig.port,
|
|
40
|
+
username: smtpConfig.username,
|
|
41
|
+
password: smtpConfig.password,
|
|
42
|
+
from_email: smtpConfig.from_email,
|
|
43
|
+
encryption: smtpConfig.encryption,
|
|
44
|
+
test_email: smtpConfig.test_email,
|
|
45
|
+
is_active: smtpConfig.is_active,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
// Log error but don't interrupt progress bar
|
|
50
|
+
logEntityError("smtp config", smtpConfig.host, error.message);
|
|
51
|
+
}
|
|
52
|
+
tracker.update();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
logSeederComplete("SMTP Config");
|
|
56
|
+
|
|
57
|
+
// Only disconnect if we created our own client
|
|
58
|
+
if (!prismaClient) {
|
|
59
|
+
await prisma.$disconnect();
|
|
60
|
+
}
|
|
61
|
+
}
|