Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit fc0b738

Browse files
committed
wip - errors
1 parent acd3ae4 commit fc0b738

1 file changed

Lines changed: 33 additions & 13 deletions

File tree

public/miscellaneous/migrate-data.cfm

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ tables = [
4646
"modules",
4747
"post_statuses",
4848
"post_types",
49-
"features",
5049
"contributor_roles",
5150
"settings",
5251
"cached_releases",
@@ -65,7 +64,8 @@ tables = [
6564
"password_resets",
6665
"user_tokens",
6766
68-
// Phase 4: Blog content (depends on users + lookups)
67+
// Phase 4: Content (depends on users + lookups)
68+
"features",
6969
"blog_posts",
7070
"tags",
7171
"blog_categories",
@@ -131,7 +131,7 @@ function targetCount(required string tableName) {
131131
function truncateTarget(required string tableName) {
132132
try {
133133
queryExecute(
134-
'DELETE FROM "#arguments.tableName#"',
134+
'TRUNCATE TABLE "#arguments.tableName#" CASCADE',
135135
{},
136136
{ datasource: TARGET_DS }
137137
);
@@ -162,6 +162,22 @@ function buildInsert(required string tableName, required query data, required nu
162162
}
163163
}
164164
165+
// Pre-scan batch to detect which columns contain date values in any row.
166+
// This ensures NULL values in those columns get CAST too (CockroachDB
167+
// requires consistent types across all rows in a multi-row VALUES clause).
168+
var dateCols = {};
169+
for (var r = arguments.startRow; r <= arguments.endRow; r++) {
170+
for (var col in columns) {
171+
var colLower = lCase(col);
172+
if (!structKeyExists(boolCols, colLower) && !structKeyExists(dateCols, colLower)) {
173+
var scanVal = arguments.data[col][r];
174+
if (!isNull(scanVal) && isDate(scanVal) && !(isSimpleValue(scanVal) && scanVal == "")) {
175+
dateCols[colLower] = true;
176+
}
177+
}
178+
}
179+
}
180+
165181
var valueClauses = [];
166182
var params = {};
167183
var paramIdx = 0;
@@ -176,22 +192,25 @@ function buildInsert(required string tableName, required query data, required nu
176192
177193
if (isNull(val) || (isSimpleValue(val) && val == "" && !structKeyExists(boolCols, colLower))) {
178194
params[paramName] = { value: "", null: true };
195+
// For columns that have dates in other rows, cast NULL to match
196+
if (structKeyExists(dateCols, colLower)) {
197+
arrayAppend(placeholders, "CAST(:#paramName# AS TIMESTAMP)");
198+
} else {
199+
arrayAppend(placeholders, ":#paramName#");
200+
}
179201
} else if (structKeyExists(boolCols, colLower)) {
180202
// Convert SQL Server BIT (1/0) to boolean string for CockroachDB
181203
var boolVal = (isBoolean(val) && val) || (isNumeric(val) && val == 1);
182204
params[paramName] = { value: boolVal ? "true" : "false", cfsqltype: "cf_sql_varchar" };
183205
arrayAppend(placeholders, "CAST(:#paramName# AS BOOLEAN)");
184-
continue;
185-
} else if (isDate(val)) {
206+
} else if (structKeyExists(dateCols, colLower)) {
186207
// Convert timestamps to ISO string to avoid JDBC {ts '...'} escape format
187208
params[paramName] = { value: dateTimeFormat(val, "yyyy-MM-dd HH:nn:ss"), cfsqltype: "cf_sql_varchar" };
188209
arrayAppend(placeholders, "CAST(:#paramName# AS TIMESTAMP)");
189-
continue;
190210
} else {
191211
params[paramName] = { value: val };
212+
arrayAppend(placeholders, ":#paramName#");
192213
}
193-
194-
arrayAppend(placeholders, ":#paramName#");
195214
}
196215
arrayAppend(valueClauses, "(#arrayToList(placeholders, ', ')#)");
197216
}
@@ -348,12 +367,13 @@ try {
348367
abort;
349368
}
350369
351-
// Disable FK checks for the migration (CockroachDB supports this per-session)
370+
// Disable FK checks for the migration (CockroachDB specific)
352371
try {
353-
queryExecute("SET session_replication_role = 'replica'", {}, { datasource: TARGET_DS });
354-
} catch (any e) {
355-
// CockroachDB may not support this — FK ordering should handle it
356-
}
372+
queryExecute("SET sql_safe_updates = false", {}, { datasource: TARGET_DS });
373+
} catch (any e) {}
374+
try {
375+
queryExecute("SET CLUSTER SETTING kv.bulk_ingest.max_index_buffer_size = '128 MiB'", {}, { datasource: TARGET_DS });
376+
} catch (any e) {}
357377
358378
writeOutput("#chr(10)#Migrating #arrayLen(tables)# tables...#chr(10)#");
359379
writeOutput(repeatString("-", 60) & chr(10));

0 commit comments

Comments
 (0)