@@ -5,15 +5,15 @@ const outFile = 'deploy/fix_seed.sql';
55
66const data = fs . readFileSync ( inFile , 'utf8' ) ;
77
8- // The transactional or buggy tables to completely skip
9- // This will clean out the old historical data that has incompatible schemas
8+ // Các bảng lỗi sẽ bị xóa khỏi output
109const skipTables = [
1110 'tickets' , 'shift_handovers' , 'shift_swap_requests' , 'payroll_calculations' ,
1211 'disposal_vouchers' , 'disposal_voucher_items' , 'inventory_counts' , 'inventory_count_items' ,
1312 'gift_redemption_history' , 'loyalty_transactions' , 'coupon_usage' , 'audit_logs' ,
1413 'cash_transactions' , 'sale_order_histories' , 'purchase_order_items' , 'purchase_orders' ,
1514 'sale_order_items' , 'sale_orders' , 'stock_movements' , 'price_expiry_alert_logs' ,
16- 'loyalty_gifts' , 'product_combos' , 'product_combo_items'
15+ 'loyalty_gifts' , 'product_combos' , 'product_combo_items' , 'purchase_history' ,
16+ 'salary_configs' , 'attendance' , 'reports'
1717] ;
1818
1919const COLUMN_MAPS = {
@@ -36,21 +36,33 @@ const COLUMN_MAPS = {
3636
3737let lines = data . split ( '\n' ) ;
3838let out = [ "SET FOREIGN_KEY_CHECKS = 0;" ] ;
39+ let isSkipping = false ;
3940
4041for ( let line of lines ) {
41- let skip = false ;
42+ if ( ! isSkipping ) {
43+ let shouldSkip = false ;
44+ for ( let table of skipTables ) {
45+ if ( line . includes ( `INSERT INTO \`${ table } \`` ) ) {
46+ shouldSkip = true ;
47+ break ;
48+ }
49+ }
4250
43- // Skip explicitly bad tables to ensure clean seed
44- for ( let table of skipTables ) {
45- if ( line . includes ( `INSERT INTO \`${ table } \`` ) ) {
46- skip = true ;
47- break ;
51+ if ( shouldSkip ) {
52+ isSkipping = true ;
53+ if ( line . includes ( ';' ) ) {
54+ isSkipping = false ;
55+ }
56+ continue ;
57+ }
58+ } else {
59+ // Đang trong mode skip nội dung statement đa dòng
60+ if ( line . includes ( ';' ) ) {
61+ isSkipping = false ; // Kết thúc statement
4862 }
63+ continue ;
4964 }
5065
51- if ( skip ) continue ;
52-
53- // Apply mapping if it's one of our target tables
5466 let processedLine = line ;
5567 for ( const [ table , cols ] of Object . entries ( COLUMN_MAPS ) ) {
5668 const re = new RegExp ( `(INSERT INTO \`${ table } \`)(?: \\\([^)]+\\\))? VALUES ` , 'g' ) ;
0 commit comments