@@ -20,27 +20,27 @@ public function up(Schema $schema): void
2020 {
2121 $ connection = $ this ->connection ;
2222
23- $ this ->migrateTable ($ connection , 'formbuilder_forms ' , ['configuration ' , 'conditionalLogic ' ]);
24- $ this ->migrateTable ($ connection , 'formbuilder_output_workflow ' , ['success_management ' ]);
25- $ this ->migrateTable ($ connection , 'formbuilder_output_workflow_channel ' , ['configuration ' , 'funnel_actions ' ]);
26- $ this ->migrateTable ($ connection , 'formbuilder_double_opt_in_session ' , ['additional_data ' ]);
23+ $ this ->migrateTable ($ connection , 'formbuilder_forms ' , ['configuration ' , 'conditionalLogic ' ], ' id ' );
24+ $ this ->migrateTable ($ connection , 'formbuilder_output_workflow ' , ['success_management ' ], ' id ' );
25+ $ this ->migrateTable ($ connection , 'formbuilder_output_workflow_channel ' , ['configuration ' , 'funnel_actions ' ], ' id ' );
26+ $ this ->migrateTable ($ connection , 'formbuilder_double_opt_in_session ' , ['additional_data ' ], ' token ' );
2727
2828 // Change column types to JSON
2929 $ this ->addSql ('ALTER TABLE formbuilder_forms MODIFY COLUMN configuration JSON ' );
3030 $ this ->addSql ('ALTER TABLE formbuilder_forms MODIFY COLUMN conditionalLogic JSON ' );
3131 $ this ->addSql ('ALTER TABLE formbuilder_output_workflow MODIFY COLUMN success_management JSON ' );
3232 $ this ->addSql ('ALTER TABLE formbuilder_output_workflow_channel MODIFY COLUMN configuration JSON ' );
3333 $ this ->addSql ('ALTER TABLE formbuilder_output_workflow_channel MODIFY COLUMN funnel_actions JSON ' );
34- $ this ->addSql ('ALTER TABLE formbuilder_double_opt_in_session MODIFY COLUMN additionalData JSON ' );
34+ $ this ->addSql ('ALTER TABLE formbuilder_double_opt_in_session MODIFY COLUMN additional_data JSON ' );
3535 }
3636
37- private function migrateTable ($ connection , $ tableName , $ columns ): void
37+ private function migrateTable ($ connection , $ tableName , $ columns, $ primaryKey = ' id ' ): void
3838 {
3939 $ columnList = implode (', ' , $ columns );
4040 $ conditions = array_map (fn ($ col ) => "$ col IS NOT NULL " , $ columns );
4141 $ whereClause = implode (' OR ' , $ conditions );
4242
43- $ result = $ connection ->executeQuery ("SELECT id , $ columnList FROM $ tableName WHERE $ whereClause " );
43+ $ result = $ connection ->executeQuery ("SELECT $ primaryKey , $ columnList FROM $ tableName WHERE $ whereClause " );
4444
4545 while ($ row = $ result ->fetchAssociative ()) {
4646 $ updates = [];
@@ -66,9 +66,9 @@ private function migrateTable($connection, $tableName, $columns): void
6666 }
6767
6868 if (!empty ($ updates )) {
69- $ values [] = $ row [' id ' ];
69+ $ values [] = $ row [$ primaryKey ];
7070 $ connection ->executeStatement (
71- "UPDATE $ tableName SET " . implode (', ' , $ updates ) . ' WHERE id = ? ' ,
71+ "UPDATE $ tableName SET " . implode (', ' , $ updates ) . " WHERE $ primaryKey = ? " ,
7272 $ values
7373 );
7474 }
0 commit comments