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

Commit 0c627ac

Browse files
committed
fix(cli): improve MySQL introspection for types and defaults
Disables NativeEnum support for MySQL to prevent loss of schema-level enums since MySQL enums are column-specific. Refines boolean and numeric type mapping to better handle synthetic boolean types and preserve decimal precision in default values. Updates default value parsing logic to correctly identify unquoted strings and avoid misinterpreting numeric literals as booleans.
1 parent f40474f commit 0c627ac

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

  • packages/cli/src/actions/pull/provider

packages/cli/src/actions/pull/provider/mysql.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export const mysql: IntrospectionProvider = {
1010
isSupportedFeature(feature) {
1111
switch (feature) {
1212
case 'NativeEnum':
13-
return true;
13+
// MySQL enums are defined inline in column definitions, not as separate types.
14+
// They can't be shared across tables like PostgreSQL enums.
15+
// Return false to preserve existing enums from the schema.
16+
return false;
1417
case 'Schema':
1518
default:
1619
return false;
@@ -94,7 +97,9 @@ export const mysql: IntrospectionProvider = {
9497
case 'String':
9598
return { type: 'varchar', precisition: 191 };
9699
case 'Boolean':
97-
return { type: 'tinyint', precisition: 1 };
100+
// Boolean maps to 'boolean' (our synthetic type from tinyint(1))
101+
// No precision needed since we handle the mapping in the query
102+
return { type: 'boolean' };
98103
case 'Int':
99104
return { type: 'int' };
100105
case 'BigInt':
@@ -202,25 +207,25 @@ export const mysql: IntrospectionProvider = {
202207
return [];
203208
}
204209

205-
// Handle boolean values
206-
if (val === 'true' || val === '1' || val === "b'1'") {
210+
// Handle boolean literal values (not numeric 0/1 which should be handled as numbers)
211+
if (val === 'true' || val === "b'1'") {
207212
factories.push(defaultAttr.addArg((ab) => ab.BooleanLiteral.setValue(true)));
208213
return factories;
209214
}
210-
if (val === 'false' || val === '0' || val === "b'0'") {
215+
if (val === 'false' || val === "b'0'") {
211216
factories.push(defaultAttr.addArg((ab) => ab.BooleanLiteral.setValue(false)));
212217
return factories;
213218
}
214219

215220
// Handle numeric values (integers and decimals)
216-
if (/^-?\d+$/.test(val)) {
221+
// Check decimals first to preserve format like 0.00
222+
if (/^-?\d+\.\d+$/.test(val)) {
223+
// Preserve the original decimal format
217224
factories.push(defaultAttr.addArg((ab) => ab.NumberLiteral.setValue(val)));
218225
return factories;
219226
}
220-
if (/^-?\d+\.\d+$/.test(val)) {
221-
// For decimal values, normalize to remove trailing zeros but keep reasonable precision
222-
const numVal = parseFloat(val);
223-
factories.push(defaultAttr.addArg((ab) => ab.NumberLiteral.setValue(String(numVal))));
227+
if (/^-?\d+$/.test(val)) {
228+
factories.push(defaultAttr.addArg((ab) => ab.NumberLiteral.setValue(val)));
224229
return factories;
225230
}
226231

@@ -263,6 +268,13 @@ export const mysql: IntrospectionProvider = {
263268
return factories;
264269
}
265270

271+
// Handle unquoted string values (MySQL sometimes returns defaults without quotes)
272+
// If it's not a number, boolean, or function, treat it as a string
273+
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(val)) {
274+
factories.push(defaultAttr.addArg((ab) => ab.StringLiteral.setValue(val)));
275+
return factories;
276+
}
277+
266278
// For any other unhandled cases, use dbgenerated
267279
factories.push(
268280
defaultAttr.addArg((a) =>

0 commit comments

Comments
 (0)