You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This just fixes and improves
#150.
With some further testing, I realized there were some issues in my
original implementation:
1. The `ON UPDATE` trigger uses `id` instead of `rowid`. This is a
regression — a query can fail now for anyone who uses `ON UPDATE` and
doesn't have an `id` column. I somehow missed that 🤦♂️
2. The trigger is deleted with every column operation, not only for
column `CHANGE`s, and it is actually missed by the `CHANGE` for creation
as well, as that branch uses `continue`/`break` and skips the trigger
creation below.
I fixed both and added test coverage.
Copy file name to clipboardExpand all lines: tests/WP_SQLite_Translator_Tests.php
+125-2Lines changed: 125 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1102,14 +1102,14 @@ public function testColumnWithOnUpdate() {
1102
1102
'name' => '___tmp_table_created_at_on_update__',
1103
1103
'tbl_name' => '_tmp_table',
1104
1104
'rootpage' => '0',
1105
-
'sql' => "CREATE TRIGGER \"___tmp_table_created_at_on_update__\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"created_at\" = CURRENT_TIMESTAMP WHERE id = NEW.id;\n\t\t\tEND",
1105
+
'sql' => "CREATE TRIGGER \"___tmp_table_created_at_on_update__\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"created_at\" = CURRENT_TIMESTAMP WHERE rowid = NEW.rowid;\n\t\t\tEND",
1106
1106
),
1107
1107
(object) array(
1108
1108
'type' => 'trigger',
1109
1109
'name' => '___tmp_table_updated_at_on_update__',
1110
1110
'tbl_name' => '_tmp_table',
1111
1111
'rootpage' => '0',
1112
-
'sql' => "CREATE TRIGGER \"___tmp_table_updated_at_on_update__\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"updated_at\" = CURRENT_TIMESTAMP WHERE id = NEW.id;\n\t\t\tEND",
1112
+
'sql' => "CREATE TRIGGER \"___tmp_table_updated_at_on_update__\"\n\t\t\tAFTER UPDATE ON \"_tmp_table\"\n\t\t\tFOR EACH ROW\n\t\t\tBEGIN\n\t\t\t UPDATE \"_tmp_table\" SET \"updated_at\" = CURRENT_TIMESTAMP WHERE rowid = NEW.rowid;\n\t\t\tEND",
1113
1113
),
1114
1114
),
1115
1115
$results
@@ -1176,6 +1176,129 @@ public function testColumnWithOnUpdate() {
0 commit comments