Skip to content

Commit 2ae652c

Browse files
kennethphoughclaude
andcommitted
fix(model-layer): renameTable typo, dropTable IF EXISTS, model-cache flush (PR A, partial)
First (safe, contained) slice of the KYTE-#325 model-layer fixes: - DBI::renameTable referenced an undefined $tbl_name_news (typo) → emitted a malformed RENAME; fixed to $tbl_name_new. Rename was effectively broken. - DBI::dropTable now uses DROP TABLE IF EXISTS (was a bare DROP that errored on an already-absent table). - DataModelController + ModelAttributeController now call Api::clearModelCache() after a schema change (create/rename/delete model, add/change/drop column), so the new struct is served immediately instead of the stale file cache (up to 1h TTL). Remaining PR-A items (next session): enforce kyte_locked on the DDL path, FK-dependency guard before drop column/table, and decimal (precision/scale) support on ModelAttribute. Then PR B = the MCP schema tools. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ac437d9 commit 2ae652c

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/Core/DBI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ public static function dropTable($tbl_name) {
716716
// db connection
717717
$con = self::getConnection();
718718

719-
$tbl_sql = "DROP TABLE `$tbl_name`";
719+
$tbl_sql = "DROP TABLE IF EXISTS `$tbl_name`";
720720

721721
$result = $con->query($tbl_sql);
722722
if($result === false) {
@@ -741,7 +741,7 @@ public static function renameTable($tbl_name_old, $tbl_name_new) {
741741
// db connection
742742
$con = self::getConnection();
743743

744-
$tbl_sql = "ALTER TABLE `$tbl_name_old` RENAME TO `$tbl_name_news`";
744+
$tbl_sql = "ALTER TABLE `$tbl_name_old` RENAME TO `$tbl_name_new`";
745745

746746
$result = $con->query($tbl_sql);
747747
if($result === false) {

src/Mvc/Controller/DataModelController.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,20 @@ public function hook_response_data($method, $o, &$r = null, &$d = null) {
204204

205205
// return to kyte db
206206
\Kyte\Core\Api::dbswitch();
207+
208+
// Invalidate the cached model struct for this app — the model is
209+
// gone, so the next request must not load it from the stale cache.
210+
\Kyte\Core\Api::clearModelCache($o->application);
211+
break;
212+
213+
case 'new':
214+
case 'update':
215+
// A create or rename changed this app's model set / a struct name;
216+
// flush the cached struct so the next request loads fresh rather
217+
// than serving the stale cache for up to its TTL.
218+
\Kyte\Core\Api::clearModelCache($o->application);
207219
break;
208-
220+
209221
default:
210222
break;
211223
}

src/Mvc/Controller/ModelAttributeController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public function hook_response_data($method, $o, &$r = null, &$d = null) {
125125
$tbl->save([
126126
'model_definition' => json_encode($model_definition)
127127
]);
128+
// Invalidate the cached model struct so the schema change (add /
129+
// change / drop column) is served immediately — the file cache
130+
// would otherwise serve the stale struct for up to its TTL (1h).
131+
\Kyte\Core\Api::clearModelCache($tbl->application);
128132
break;
129133

130134
default:

0 commit comments

Comments
 (0)