Report hasn't been filed before.
What version of drizzle-orm are you using?
1.0.0-beta.20
What version of drizzle-kit are you using?
1.0.0-beta.20
Other packages
No response
Describe the Bug
What is the undesired behavior?
When running drizzle-kit pull on a MySQL database that contains a View with a VARCHAR column, the generated schema file creates the view column as varchar() without the required length argument.
Since the MySQL varchar type in Drizzle requires a length configuration object, this generates invalid TypeScript code and breaks compilation with the error: Expected 1-2 arguments, but got 0.
What are the steps to reproduce it?
- Create a MySQL table with a
VARCHAR column and a view based on it:
CREATE TABLE base_table (
id INT,
name VARCHAR(50)
);
CREATE VIEW broken_view AS SELECT * FROM base_table;
-
Run drizzle-kit pull to introspect the database.
-
Check the generated schema.ts file.
The table is generated correctly (varchar({ length: 50 })), but the view is missing the length parameter:
// Table is correct
export const baseTable = mysqlTable("base_table", {
id: int(),
name: varchar({ length: 50 }),
});
// View is broken
export const brokenView = mysqlView("broken_view", {
id: int(),
name: varchar(), // <--- TypeScript error here
}).as(sql`...`);
Also, you can use this repo with pnpm repro:crash
What is the desired result?
The generated mysqlView should correctly infer the length of the string column and generate varchar({ length: 50 }), just like it does for base tables.
Root Cause
I was digging into the source code and found exactly why this happens. Inside the fromDatabase function for MySQL (where the // VIEWS block iterates over viewColumns), the mapping is using DATA_TYPE instead of COLUMN_TYPE.
In information_schema.columns, DATA_TYPE only returns "varchar", whereas COLUMN_TYPE returns "varchar(50)". Since the ddlToTypeScript generator only receives "varchar", it doesn't know the length.
Report hasn't been filed before.
What version of
drizzle-ormare you using?1.0.0-beta.20
What version of
drizzle-kitare you using?1.0.0-beta.20
Other packages
No response
Describe the Bug
What is the undesired behavior?
When running
drizzle-kit pullon a MySQL database that contains a View with aVARCHARcolumn, the generated schema file creates the view column asvarchar()without the requiredlengthargument.Since the MySQL
varchartype in Drizzle requires a length configuration object, this generates invalid TypeScript code and breaks compilation with the error:Expected 1-2 arguments, but got 0.What are the steps to reproduce it?
VARCHARcolumn and a view based on it:Run drizzle-kit pull to introspect the database.
Check the generated schema.ts file.
The table is generated correctly (varchar({ length: 50 })), but the view is missing the length parameter:
Also, you can use this repo with
pnpm repro:crashWhat is the desired result?
The generated mysqlView should correctly infer the length of the string column and generate varchar({ length: 50 }), just like it does for base tables.
Root Cause
I was digging into the source code and found exactly why this happens. Inside the fromDatabase function for MySQL (where the // VIEWS block iterates over viewColumns), the mapping is using DATA_TYPE instead of COLUMN_TYPE.
In information_schema.columns, DATA_TYPE only returns "varchar", whereas COLUMN_TYPE returns "varchar(50)". Since the ddlToTypeScript generator only receives "varchar", it doesn't know the length.