velocious 1.0.724 → 1.0.725

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,33 @@ import parseInnodbDeadlockSummary from "./deadlock-diagnostic-parser.js"
34
34
  */
35
35
  const MYSQL_INDEFINITE_LOCK_TIMEOUT_SECONDS = 60 * 60 * 24 * 365
36
36
  const INNODB_DEADLOCK_CAPTURE_TIMEOUT_MS = 250
37
+ const INFORMATION_SCHEMA_STRING_LITERAL_PATTERN = /^[A-Za-z0-9 _.,:/@+-]*$/
38
+
39
+ /**
40
+ * `information_schema.COLUMNS` reports a string column default as its SQL literal
41
+ * (quoted, e.g. `'normal'`), while `SHOW FULL COLUMNS` reports the bare value
42
+ * (`normal`). Column consumers key on the `SHOW FULL COLUMNS` shape: the schema
43
+ * cloner's simple-default pattern rejects the quoted form, so a batch-read string
44
+ * default would be dropped from the cloned column and an insert that omits it then
45
+ * fails with ER_NO_DEFAULT_FOR_FIELD on the tenant copy. Normalize the batch read
46
+ * to the same shape the per-table read produces.
47
+ * @param {unknown} defaultValue - Raw `COLUMN_DEFAULT` value from the batch read.
48
+ * @returns {unknown} - The default in the `SHOW FULL COLUMNS` shape.
49
+ */
50
+ function normalizeInformationSchemaDefault(defaultValue) {
51
+ if (typeof defaultValue !== "string") return defaultValue
52
+
53
+ if (defaultValue.length >= 2 && defaultValue.startsWith("'") && defaultValue.endsWith("'")) {
54
+ const innerValue = defaultValue.slice(1, -1)
55
+
56
+ // Only plain string literals are unquoted; expression defaults (e.g.
57
+ // DEFAULT '''UUID()''') keep their stored form, which SHOW FULL COLUMNS
58
+ // also reports verbatim.
59
+ if (INFORMATION_SCHEMA_STRING_LITERAL_PATTERN.test(innerValue)) return innerValue
60
+ }
61
+
62
+ return defaultValue
63
+ }
37
64
 
38
65
  export default class VelociousDatabaseDriversMysql extends Base{
39
66
  /** @type {import("mysql").Pool | undefined} */
@@ -807,6 +834,8 @@ export default class VelociousDatabaseDriversMysql extends Base{
807
834
 
808
835
  if (!table) continue
809
836
 
837
+ row.Default = normalizeInformationSchemaDefault(row.Default)
838
+
810
839
  const columns = columnsByTable.get(tableName) || []
811
840
 
812
841
  columns.push(new Column(table, /** @type {Record<string, ReturnType<typeof JSON.parse>>} */ (row)))