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,276 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test script for optimized core data seeders
|
|
5
|
+
* Validates the new batch processing, retry logic, and progress tracking features
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { PrismaClient } from '../../src/prisma/index.js';
|
|
9
|
+
import { seedUsers } from './user.seed.js';
|
|
10
|
+
import { seedRoles } from './role.seed.js';
|
|
11
|
+
import { seedPermissions } from './permission.seed.js';
|
|
12
|
+
import { seedDepartments } from './department.seed.js';
|
|
13
|
+
import { seedCurrencies } from './currency.seed.js';
|
|
14
|
+
import colors from 'colors';
|
|
15
|
+
|
|
16
|
+
const prisma = new PrismaClient({
|
|
17
|
+
log: [
|
|
18
|
+
{ level: 'query', emit: 'event' },
|
|
19
|
+
{ level: 'error', emit: 'stdout' },
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Query counter for performance monitoring
|
|
24
|
+
let queryCount = 0;
|
|
25
|
+
prisma.$on('query', () => {
|
|
26
|
+
queryCount++;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Test configuration for monitoring seeder performance
|
|
31
|
+
*/
|
|
32
|
+
const testConfig = {
|
|
33
|
+
enableTiming: true,
|
|
34
|
+
enableMemoryMonitoring: true,
|
|
35
|
+
enableQueryCounting: true,
|
|
36
|
+
logDetailedResults: true
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Performance monitoring utility
|
|
41
|
+
*/
|
|
42
|
+
class PerformanceMonitor {
|
|
43
|
+
constructor(entityName) {
|
|
44
|
+
this.entityName = entityName;
|
|
45
|
+
this.startTime = Date.now();
|
|
46
|
+
this.startMemory = process.memoryUsage();
|
|
47
|
+
this.startQueryCount = queryCount;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
complete() {
|
|
51
|
+
const endTime = Date.now();
|
|
52
|
+
const endMemory = process.memoryUsage();
|
|
53
|
+
const endQueryCount = queryCount;
|
|
54
|
+
|
|
55
|
+
const duration = (endTime - this.startTime) / 1000;
|
|
56
|
+
const memoryDelta = {
|
|
57
|
+
rss: (endMemory.rss - this.startMemory.rss) / 1024 / 1024,
|
|
58
|
+
heapUsed: (endMemory.heapUsed - this.startMemory.heapUsed) / 1024 / 1024,
|
|
59
|
+
heapTotal: (endMemory.heapTotal - this.startMemory.heapTotal) / 1024 / 1024
|
|
60
|
+
};
|
|
61
|
+
const queryDelta = endQueryCount - this.startQueryCount;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
entityName: this.entityName,
|
|
65
|
+
duration,
|
|
66
|
+
memoryDelta,
|
|
67
|
+
queryDelta,
|
|
68
|
+
finalMemory: {
|
|
69
|
+
rss: endMemory.rss / 1024 / 1024,
|
|
70
|
+
heapUsed: endMemory.heapUsed / 1024 / 1024,
|
|
71
|
+
heapTotal: endMemory.heapTotal / 1024 / 1024
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Test a single core seeder with performance monitoring
|
|
79
|
+
*/
|
|
80
|
+
async function testSeeder(seederFunction, entityName) {
|
|
81
|
+
console.log(colors.cyan(`\n🧪 Testing ${entityName} seeder...`));
|
|
82
|
+
|
|
83
|
+
const monitor = new PerformanceMonitor(entityName);
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const result = await seederFunction(prisma);
|
|
87
|
+
const performance = monitor.complete();
|
|
88
|
+
|
|
89
|
+
// Log results
|
|
90
|
+
if (testConfig.logDetailedResults) {
|
|
91
|
+
console.log(colors.green(`✅ ${entityName} seeder completed successfully`));
|
|
92
|
+
|
|
93
|
+
if (result && typeof result === 'object') {
|
|
94
|
+
console.log(colors.gray(` 📊 Results:`));
|
|
95
|
+
console.log(colors.gray(` - Total processed: ${result.totalProcessed || 'N/A'}`));
|
|
96
|
+
console.log(colors.gray(` - Total created: ${result.totalCreated || 'N/A'}`));
|
|
97
|
+
console.log(colors.gray(` - Total updated: ${result.totalUpdated || 'N/A'}`));
|
|
98
|
+
console.log(colors.gray(` - Errors: ${result.errors?.length || 0}`));
|
|
99
|
+
|
|
100
|
+
if (result.config) {
|
|
101
|
+
console.log(colors.gray(` ⚙️ Configuration:`));
|
|
102
|
+
console.log(colors.gray(` - Batch size: ${result.config.batchSize}`));
|
|
103
|
+
console.log(colors.gray(` - Max concurrent batches: ${result.config.maxConcurrentBatches}`));
|
|
104
|
+
console.log(colors.gray(` - Retry attempts: ${result.config.retryAttempts}`));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (testConfig.enableTiming) {
|
|
109
|
+
console.log(colors.gray(` ⏱️ Duration: ${performance.duration.toFixed(2)}s`));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (testConfig.enableQueryCounting) {
|
|
113
|
+
console.log(colors.gray(` 🔍 Queries executed: ${performance.queryDelta}`));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (testConfig.enableMemoryMonitoring) {
|
|
117
|
+
console.log(colors.gray(` 💾 Memory delta (MB):`));
|
|
118
|
+
console.log(colors.gray(` - RSS: ${performance.memoryDelta.rss.toFixed(2)}`));
|
|
119
|
+
console.log(colors.gray(` - Heap Used: ${performance.memoryDelta.heapUsed.toFixed(2)}`));
|
|
120
|
+
console.log(colors.gray(` - Heap Total: ${performance.memoryDelta.heapTotal.toFixed(2)}`));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { success: true, performance, result };
|
|
125
|
+
} catch (error) {
|
|
126
|
+
const performance = monitor.complete();
|
|
127
|
+
|
|
128
|
+
console.log(colors.red(`❌ ${entityName} seeder failed`));
|
|
129
|
+
console.log(colors.red(` Error: ${error.message}`));
|
|
130
|
+
|
|
131
|
+
if (testConfig.enableTiming) {
|
|
132
|
+
console.log(colors.gray(` ⏱️ Duration before failure: ${performance.duration.toFixed(2)}s`));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { success: false, performance, error: error.message };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Run comprehensive test of all core seeders
|
|
141
|
+
*/
|
|
142
|
+
async function runCoreSeederTests() {
|
|
143
|
+
console.log(colors.bold.cyan('\n🚀 CORE SEEDER OPTIMIZATION TEST'));
|
|
144
|
+
console.log(colors.gray('Testing optimized core data seeders with batch processing and retry logic\n'));
|
|
145
|
+
|
|
146
|
+
const startTime = Date.now();
|
|
147
|
+
const startMemory = process.memoryUsage();
|
|
148
|
+
const startQueryCount = queryCount;
|
|
149
|
+
|
|
150
|
+
// Define test sequence (order matters for dependencies)
|
|
151
|
+
const testSequence = [
|
|
152
|
+
{ name: 'Departments', seeder: seedDepartments },
|
|
153
|
+
{ name: 'Currencies', seeder: seedCurrencies },
|
|
154
|
+
{ name: 'Users', seeder: seedUsers },
|
|
155
|
+
{ name: 'Roles', seeder: seedRoles },
|
|
156
|
+
{ name: 'Permissions', seeder: seedPermissions }
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
const results = [];
|
|
160
|
+
let totalErrors = 0;
|
|
161
|
+
|
|
162
|
+
// Run each seeder test
|
|
163
|
+
for (const test of testSequence) {
|
|
164
|
+
const testResult = await testSeeder(test.seeder, test.name);
|
|
165
|
+
results.push(testResult);
|
|
166
|
+
|
|
167
|
+
if (!testResult.success) {
|
|
168
|
+
totalErrors++;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Small delay between tests to allow for cleanup
|
|
172
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Calculate overall performance
|
|
176
|
+
const totalTime = (Date.now() - startTime) / 1000;
|
|
177
|
+
const totalMemory = process.memoryUsage();
|
|
178
|
+
const totalMemoryDelta = {
|
|
179
|
+
rss: (totalMemory.rss - startMemory.rss) / 1024 / 1024,
|
|
180
|
+
heapUsed: (totalMemory.heapUsed - startMemory.heapUsed) / 1024 / 1024
|
|
181
|
+
};
|
|
182
|
+
const totalQueryDelta = queryCount - startQueryCount;
|
|
183
|
+
|
|
184
|
+
// Print summary
|
|
185
|
+
console.log(colors.bold.cyan('\n📈 TEST SUMMARY'));
|
|
186
|
+
console.log(colors.gray('═'.repeat(60)));
|
|
187
|
+
|
|
188
|
+
console.log(colors.green(`✅ Successful seeders: ${results.filter(r => r.success).length}/${results.length}`));
|
|
189
|
+
console.log(colors.red(`❌ Failed seeders: ${totalErrors}`));
|
|
190
|
+
console.log(colors.gray(`⏱️ Total time: ${totalTime.toFixed(2)}s`));
|
|
191
|
+
console.log(colors.gray(`🔍 Total queries: ${totalQueryDelta}`));
|
|
192
|
+
console.log(colors.gray(`💾 Total memory delta: ${totalMemoryDelta.rss.toFixed(2)} MB RSS, ${totalMemoryDelta.heapUsed.toFixed(2)} MB Heap`));
|
|
193
|
+
|
|
194
|
+
// Performance analysis
|
|
195
|
+
const avgTimePerSeeder = totalTime / results.length;
|
|
196
|
+
const avgQueriesPerSeeder = totalQueryDelta / results.length;
|
|
197
|
+
|
|
198
|
+
console.log(colors.cyan('\n📊 PERFORMANCE ANALYSIS'));
|
|
199
|
+
console.log(colors.gray(`⏱️ Average time per seeder: ${avgTimePerSeeder.toFixed(2)}s`));
|
|
200
|
+
console.log(colors.gray(`🔍 Average queries per seeder: ${avgQueriesPerSeeder.toFixed(0)}`));
|
|
201
|
+
|
|
202
|
+
// Individual performance breakdown
|
|
203
|
+
console.log(colors.cyan('\n🔍 INDIVIDUAL PERFORMANCE'));
|
|
204
|
+
results.forEach(result => {
|
|
205
|
+
const status = result.success ? colors.green('✅') : colors.red('❌');
|
|
206
|
+
const timing = result.performance.duration.toFixed(2) + 's';
|
|
207
|
+
const queries = result.performance.queryDelta;
|
|
208
|
+
const memory = result.performance.memoryDelta.heapUsed.toFixed(1) + 'MB';
|
|
209
|
+
|
|
210
|
+
console.log(`${status} ${result.performance.entityName.padEnd(12)} - ${timing.padStart(8)} | ${queries.toString().padStart(3)} queries | ${memory.padStart(8)} heap`);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Optimization recommendations
|
|
214
|
+
console.log(colors.cyan('\n💡 OPTIMIZATION INSIGHTS'));
|
|
215
|
+
|
|
216
|
+
const slowestSeeder = results.reduce((prev, current) =>
|
|
217
|
+
(prev.performance.duration > current.performance.duration) ? prev : current
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const mostQueriesSeeder = results.reduce((prev, current) =>
|
|
221
|
+
(prev.performance.queryDelta > current.performance.queryDelta) ? prev : current
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
console.log(colors.yellow(`⚠️ Slowest seeder: ${slowestSeeder.performance.entityName} (${slowestSeeder.performance.duration.toFixed(2)}s)`));
|
|
225
|
+
console.log(colors.yellow(`⚠️ Most queries: ${mostQueriesSeeder.performance.entityName} (${mostQueriesSeeder.performance.queryDelta} queries)`));
|
|
226
|
+
|
|
227
|
+
if (totalMemoryDelta.heapUsed > 50) {
|
|
228
|
+
console.log(colors.yellow(`⚠️ High memory usage detected: ${totalMemoryDelta.heapUsed.toFixed(2)} MB heap increase`));
|
|
229
|
+
console.log(colors.gray(' Consider reducing batch sizes or enabling more aggressive garbage collection'));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Final status
|
|
233
|
+
if (totalErrors === 0) {
|
|
234
|
+
console.log(colors.bold.green('\n🎉 ALL CORE SEEDERS PASSED! Optimizations are working correctly.'));
|
|
235
|
+
} else {
|
|
236
|
+
console.log(colors.bold.red(`\n💥 ${totalErrors} SEEDER(S) FAILED. Check the error messages above.`));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
success: totalErrors === 0,
|
|
241
|
+
totalTime,
|
|
242
|
+
totalErrors,
|
|
243
|
+
results
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Main test execution
|
|
249
|
+
*/
|
|
250
|
+
async function main() {
|
|
251
|
+
try {
|
|
252
|
+
const testResults = await runCoreSeederTests();
|
|
253
|
+
|
|
254
|
+
if (testResults.success) {
|
|
255
|
+
console.log(colors.bold.green('\n✅ Core seeder optimization test completed successfully!'));
|
|
256
|
+
process.exit(0);
|
|
257
|
+
} else {
|
|
258
|
+
console.log(colors.bold.red('\n❌ Core seeder optimization test completed with errors!'));
|
|
259
|
+
process.exit(1);
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error(colors.red('\n💥 Test execution failed:'));
|
|
263
|
+
console.error(colors.red(error.message));
|
|
264
|
+
console.error(colors.gray(error.stack));
|
|
265
|
+
process.exit(1);
|
|
266
|
+
} finally {
|
|
267
|
+
await prisma.$disconnect();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Run tests if this script is executed directly
|
|
272
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
273
|
+
main();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export { runCoreSeederTests };
|
|
@@ -0,0 +1,66 @@
|
|
|
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 seedUserDepartments(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("user departments");
|
|
15
|
+
|
|
16
|
+
// Load user-departments from JSON
|
|
17
|
+
const userDepartmentData = loadCoreData("user-departments");
|
|
18
|
+
|
|
19
|
+
// Create progress tracker
|
|
20
|
+
const tracker = createProgressTracker(
|
|
21
|
+
userDepartmentData.length,
|
|
22
|
+
"user departments"
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
for (const userDepartment of userDepartmentData) {
|
|
26
|
+
try {
|
|
27
|
+
await prisma.userDepartment.upsert({
|
|
28
|
+
where: {
|
|
29
|
+
id: userDepartment.id,
|
|
30
|
+
},
|
|
31
|
+
update: {
|
|
32
|
+
user_id: userDepartment.user_id,
|
|
33
|
+
department_id: userDepartment.department_id,
|
|
34
|
+
created_at: new Date(userDepartment.created_at),
|
|
35
|
+
created_by: userDepartment.created_by,
|
|
36
|
+
updated_at: new Date(userDepartment.updated_at),
|
|
37
|
+
updated_by: userDepartment.updated_by,
|
|
38
|
+
},
|
|
39
|
+
create: {
|
|
40
|
+
id: userDepartment.id,
|
|
41
|
+
user_id: userDepartment.user_id,
|
|
42
|
+
department_id: userDepartment.department_id,
|
|
43
|
+
created_at: new Date(userDepartment.created_at),
|
|
44
|
+
created_by: userDepartment.created_by,
|
|
45
|
+
updated_at: new Date(userDepartment.updated_at),
|
|
46
|
+
updated_by: userDepartment.updated_by,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// Log error but don't interrupt progress bar
|
|
51
|
+
logEntityError(
|
|
52
|
+
"user department",
|
|
53
|
+
`ID: ${userDepartment.id}`,
|
|
54
|
+
error.message
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
tracker.update();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
logSeederComplete("User departments");
|
|
61
|
+
|
|
62
|
+
// Only disconnect if we created our own client
|
|
63
|
+
if (!prismaClient) {
|
|
64
|
+
await prisma.$disconnect();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PrismaClient } from "../../src/prisma/index.js";
|
|
2
|
+
import { loadCoreData } from "./utils/json-loader.js";
|
|
3
|
+
import { seedCoreEntity } from "./utils/core-seeder.js";
|
|
4
|
+
|
|
5
|
+
export const seedUserEventConfigurations = async (prismaClient) => {
|
|
6
|
+
// Use the passed client or create new one only if needed (for standalone testing)
|
|
7
|
+
const prisma = prismaClient || new PrismaClient();
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
// Load user event configuration data from JSON
|
|
11
|
+
const userEventConfigurations = loadCoreData("user-event-configuration");
|
|
12
|
+
|
|
13
|
+
// Process user event configurations with optimized core seeder
|
|
14
|
+
const result = await seedCoreEntity(
|
|
15
|
+
prisma,
|
|
16
|
+
userEventConfigurations,
|
|
17
|
+
"user event configurations",
|
|
18
|
+
{
|
|
19
|
+
model: "userEventConfiguration",
|
|
20
|
+
whereField: "slug",
|
|
21
|
+
updateFields: ["name", "is_active", "is_editable", "created_by"],
|
|
22
|
+
createFields: [
|
|
23
|
+
"name",
|
|
24
|
+
"slug",
|
|
25
|
+
"is_active",
|
|
26
|
+
"is_editable",
|
|
27
|
+
"created_by",
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
profile: "stability", // User event configurations are core entities
|
|
32
|
+
enableRetries: true,
|
|
33
|
+
logProgress: true,
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(`Failed to seed user event configurations: ${error.message}`);
|
|
40
|
+
throw error;
|
|
41
|
+
} finally {
|
|
42
|
+
// Only disconnect if we created our own client
|
|
43
|
+
if (!prismaClient) {
|
|
44
|
+
await prisma.$disconnect();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { PrismaClient } from "../../src/prisma/index.js";
|
|
2
|
+
import { CURRENT_ADMIN_USER_EMAIL } from "./utils/config.js";
|
|
3
|
+
import {
|
|
4
|
+
logSeederStart,
|
|
5
|
+
logSeederComplete,
|
|
6
|
+
logEntityError,
|
|
7
|
+
} from "./utils/progress-tracker.js";
|
|
8
|
+
|
|
9
|
+
export async function seedUserRole(prismaClient) {
|
|
10
|
+
// Use the passed client or create new one only if needed (for standalone testing)
|
|
11
|
+
const prisma = prismaClient || new PrismaClient();
|
|
12
|
+
|
|
13
|
+
logSeederStart("user role");
|
|
14
|
+
|
|
15
|
+
const admin = await prisma.user.findFirst({
|
|
16
|
+
where: { email_id: CURRENT_ADMIN_USER_EMAIL },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (!admin) {
|
|
20
|
+
console.log(
|
|
21
|
+
`Warning: Admin user with email ${CURRENT_ADMIN_USER_EMAIL} not found. Skipping user role assignment.`
|
|
22
|
+
);
|
|
23
|
+
logSeederComplete("User role");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const adminRole = await prisma.role.findFirst({
|
|
28
|
+
where: { slug: "super_admin" },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (!adminRole) {
|
|
32
|
+
console.log(
|
|
33
|
+
`Warning: Super admin role not found. Skipping user role assignment.`
|
|
34
|
+
);
|
|
35
|
+
logSeederComplete("User role");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const userRole = await prisma.userRole.findFirst({
|
|
40
|
+
where: { user_id: admin.id },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (userRole === null) {
|
|
44
|
+
console.log(
|
|
45
|
+
`Assigning role ${adminRole.role_name} to user ${
|
|
46
|
+
admin.name || admin.email_id
|
|
47
|
+
}`
|
|
48
|
+
);
|
|
49
|
+
try {
|
|
50
|
+
await prisma.userRole.create({
|
|
51
|
+
data: {
|
|
52
|
+
user_id: admin.id,
|
|
53
|
+
role_id: adminRole.id,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
console.log(`Role assigned successfully`);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
logEntityError("user role", admin.email_id, error.message);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
console.log(
|
|
62
|
+
`User ${
|
|
63
|
+
admin.name || admin.email_id
|
|
64
|
+
} already has role assignments. Skipping.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
logSeederComplete("User role");
|
|
69
|
+
|
|
70
|
+
// Only disconnect if we created our own client
|
|
71
|
+
if (!prismaClient) {
|
|
72
|
+
await prisma.$disconnect();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { PrismaClient } from "../../src/prisma/index.js";
|
|
2
|
+
import { loadCoreData } from "./utils/json-loader.js";
|
|
3
|
+
import * as bcrypt from "bcrypt";
|
|
4
|
+
import { createCoreSeeder } from "./utils/core-seeder.js";
|
|
5
|
+
import { CURRENT_ADMIN_USER_EMAIL } from "./utils/config.js";
|
|
6
|
+
import { getSeederConfig } from "./utils/seeder-config-mapper.js";
|
|
7
|
+
import { createPerformanceConfig } from "./utils/performance-config.js";
|
|
8
|
+
|
|
9
|
+
export async function seedUsers(prismaClient, seederManager = null) {
|
|
10
|
+
// Use the passed client or create new one only if needed (for standalone testing)
|
|
11
|
+
const prisma = prismaClient || new PrismaClient();
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
// Load users from JSON
|
|
15
|
+
const userData = loadCoreData("users");
|
|
16
|
+
|
|
17
|
+
// Get configuration from seeder manager or create default
|
|
18
|
+
let config;
|
|
19
|
+
if (seederManager) {
|
|
20
|
+
config = seederManager.getConfig('user');
|
|
21
|
+
console.log(`\n=== User Seeder Configuration ===`);
|
|
22
|
+
console.log(`Category: ${config.category}`);
|
|
23
|
+
console.log(`Batch Size: ${config.batchSize}`);
|
|
24
|
+
console.log(`Max Concurrent: ${config.maxConcurrentBatches}`);
|
|
25
|
+
console.log(`Fallback: ${config.fallback || 'No'}`);
|
|
26
|
+
console.log(`=====================================\n`);
|
|
27
|
+
} else {
|
|
28
|
+
// Fallback to default performance config
|
|
29
|
+
const perfConfig = createPerformanceConfig({ profile: 'stability' });
|
|
30
|
+
config = perfConfig.getConfig('core', 'users');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Create optimized core seeder with configuration from seeder manager
|
|
34
|
+
const coreSeeder = createCoreSeeder(prisma, {
|
|
35
|
+
performanceConfig: seederManager?.performanceConfig || { profile: 'stability' },
|
|
36
|
+
enableRetries: true,
|
|
37
|
+
logProgress: true
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Create processor function for user upserts with password hashing
|
|
41
|
+
const userProcessor = async (user, options = {}) => {
|
|
42
|
+
try {
|
|
43
|
+
const email_id = options.isFirstUser ? CURRENT_ADMIN_USER_EMAIL : user.email_id;
|
|
44
|
+
|
|
45
|
+
// Hash password for security
|
|
46
|
+
const salt = await bcrypt.genSalt();
|
|
47
|
+
const hashedPassword = await bcrypt.hash(user.password, salt);
|
|
48
|
+
|
|
49
|
+
const result = await prisma.user.upsert({
|
|
50
|
+
where: {
|
|
51
|
+
unique_id: user.unique_id,
|
|
52
|
+
},
|
|
53
|
+
update: {
|
|
54
|
+
name: user.name,
|
|
55
|
+
first_name: user.first_name,
|
|
56
|
+
middle_name: user.middle_name,
|
|
57
|
+
last_name: user.last_name,
|
|
58
|
+
country_code: user.country_code,
|
|
59
|
+
mobile_number: user.mobile_number,
|
|
60
|
+
access_token_expiry: user.access_token_expiry,
|
|
61
|
+
password: hashedPassword,
|
|
62
|
+
},
|
|
63
|
+
create: {
|
|
64
|
+
unique_id: user.unique_id,
|
|
65
|
+
name: user.name,
|
|
66
|
+
first_name: user.first_name,
|
|
67
|
+
middle_name: user.middle_name,
|
|
68
|
+
last_name: user.last_name,
|
|
69
|
+
email_id: email_id,
|
|
70
|
+
password: hashedPassword,
|
|
71
|
+
country_code: user.country_code,
|
|
72
|
+
mobile_number: user.mobile_number,
|
|
73
|
+
access_token_expiry: user.access_token_expiry,
|
|
74
|
+
status: "Active",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Mark first user as processed
|
|
79
|
+
if (options.isFirstUser) {
|
|
80
|
+
options.isFirstUser = false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Simple heuristic to determine if this was create or update
|
|
84
|
+
const isNewRecord = result.created_at &&
|
|
85
|
+
new Date(result.created_at).getTime() > Date.now() - 5000;
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
created: isNewRecord,
|
|
89
|
+
updated: !isNewRecord
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Track first user state across batches
|
|
97
|
+
const processorOptions = { isFirstUser: true };
|
|
98
|
+
|
|
99
|
+
// Process users with optimized core seeder
|
|
100
|
+
const result = await coreSeeder.processCore(
|
|
101
|
+
userData,
|
|
102
|
+
userProcessor,
|
|
103
|
+
'users',
|
|
104
|
+
processorOptions
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
} finally {
|
|
109
|
+
// Only disconnect if we created our own client
|
|
110
|
+
if (!prismaClient) {
|
|
111
|
+
await prisma.$disconnect();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|