2323use DreamFactory \Core \Models \Service ;
2424use DreamFactory \Core \Utility \ResourcesWrapper ;
2525use GraphQL \Type \Definition \Type ;
26+ use Illuminate \Support \Str ;
2627use ServiceManager ;
2728use DreamFactory \Core \Database \Components \Schema ;
2829use DreamFactory \Core \Resources \BaseRestResource ;
@@ -65,6 +66,11 @@ class DbSchemaResource extends BaseRestResource
6566 'db_function ' ,
6667 'is_virtual ' ,
6768 'is_aggregate ' ,
69+ 'is_foreign_key ' ,
70+ 'ref_table ' ,
71+ 'ref_field ' ,
72+ 'ref_on_update ' ,
73+ 'ref_on_delete ' ,
6874 ];
6975 /**
7076 * @var array
@@ -1732,7 +1738,12 @@ public function updateSchema($tables, $allow_merge = false, $allow_delete = fals
17321738 $ this ->setSchemaTableExtras ($ tableExtras );
17331739 }
17341740 if (!empty ($ fieldExtras )) {
1741+ // DEBUG: Log what's being saved to database
1742+ \Log::info ('updateSchema - SAVING to database - fieldExtras: ' , $ fieldExtras );
17351743 $ this ->setSchemaFieldExtras ($ fieldExtras );
1744+ \Log::info ('updateSchema - SAVE COMPLETE ' );
1745+ } else {
1746+ \Log::info ('updateSchema - NO fieldExtras to save (array is empty) ' );
17361747 }
17371748 if (!empty ($ fieldDrops )) {
17381749 foreach ($ fieldDrops as $ table => $ dropped ) {
@@ -1878,8 +1889,17 @@ protected function buildTableFields(
18781889
18791890 $ oldArray = $ oldField ->toArray ();
18801891 $ diffFields = array_diff ($ this ->fieldExtras , ['picklist ' , 'validation ' , 'db_function ' ]);
1892+
1893+ // DEBUG: Log what we're comparing
1894+ \Log::info ("UPDATE FIELD ' $ name' - diffFields: " , $ diffFields );
1895+ \Log::info ("UPDATE FIELD ' $ name' - field data for comparison: " , array_only ($ field , $ diffFields ));
1896+ \Log::info ("UPDATE FIELD ' $ name' - oldArray data for comparison: " , array_only ($ oldArray , $ diffFields ));
1897+
18811898 $ extraNew = array_diff_assoc (array_only ($ field , $ diffFields ), array_only ($ oldArray , $ diffFields ));
18821899
1900+ // DEBUG: Log extracted extras
1901+ \Log::info ("UPDATE FIELD ' $ name' - extraNew (changes detected): " , $ extraNew );
1902+
18831903 if (array_key_exists ('picklist ' , $ field )) {
18841904 $ picklist = (array )array_get ($ field , 'picklist ' );
18851905 $ oldPicklist = (array )$ oldField ->picklist ;
@@ -1926,11 +1946,17 @@ protected function buildTableFields(
19261946 }
19271947
19281948 // if empty, nothing to do here, check extras
1949+ \Log::info ("UPDATE FIELD ' $ name' - settingsNew check - empty= " . (empty ($ settingsNew ) ? 'YES ' : 'NO ' ));
19291950 if (empty ($ settingsNew )) {
19301951 if (!empty ($ extraNew )) {
19311952 $ extraNew ['table ' ] = $ table_schema ->name ;
19321953 $ extraNew ['field ' ] = $ name ;
19331954 $ extras [] = $ extraNew ;
1955+
1956+ // DEBUG: Log early exit save
1957+ \Log::info ("UPDATE FIELD ' $ name' - EARLY EXIT SAVE - Adding to extras: " , $ extraNew );
1958+ } else {
1959+ \Log::info ("UPDATE FIELD ' $ name' - EARLY EXIT - No extras to save " );
19341960 }
19351961
19361962 continue ;
@@ -1988,6 +2014,12 @@ protected function buildTableFields(
19882014 $ extraNew ['table ' ] = $ table_schema ->name ;
19892015 $ extraNew ['field ' ] = $ name ;
19902016 $ extras [] = $ extraNew ;
2017+
2018+ // DEBUG: Log what's being added to extras array
2019+ \Log::info ("SAVING FIELD ' $ name' - Adding to extras array: " , $ extraNew );
2020+ } else {
2021+ // DEBUG: Log when extraNew is empty
2022+ \Log::info ("SAVING FIELD ' $ name' - extraNew is EMPTY, nothing to save " );
19912023 }
19922024 }
19932025
@@ -2011,6 +2043,9 @@ protected function buildTableFields(
20112043 }
20122044 }
20132045
2046+ // DEBUG: Log what extras are being returned
2047+ \Log::info ('buildTableFields - RETURNING extras array: ' , $ extras );
2048+
20142049 return [
20152050 'columns ' => $ columns ,
20162051 'alter_columns ' => $ alterColumns ,
@@ -2301,7 +2336,24 @@ public function buildTableRelated(
23012336 */
23022337 protected function cleanClientField (array &$ field )
23032338 {
2339+ // DEBUG: Log original field data
2340+ \Log::info ('cleanClientField - ORIGINAL field data: ' , $ field );
2341+
2342+ // Convert camelCase keys to snake_case first
2343+ $ converted = [];
2344+ foreach ($ field as $ key => $ value ) {
2345+ $ snakeKey = Str::snake ($ key );
2346+ $ converted [$ snakeKey ] = $ value ;
2347+ }
2348+ $ field = $ converted ;
2349+
2350+ // DEBUG: Log after snake_case conversion
2351+ \Log::info ('cleanClientField - AFTER snake_case conversion: ' , $ field );
2352+
23042353 $ field = array_change_key_case ($ field , CASE_LOWER );
2354+
2355+ // DEBUG: Log after lowercase conversion
2356+ \Log::info ('cleanClientField - AFTER lowercase conversion: ' , $ field );
23052357 if (empty ($ name = array_get ($ field , 'name ' ))) {
23062358 throw new \Exception ("Invalid schema detected - no name element. " );
23072359 }
0 commit comments