drizzle-orm: [BUG]: Can't parse float(8,2) from database (precision and scale and/or unsigned breaks float types)

What version of drizzle-orm are you using?

0.28.5

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

Then the schema file fails to generate the column definition/type for any column defined as float(x,y)

When I call drizzle-kit introspect:mysql, I get this in my output: uknown float(8,2)

This is what the generated schema.ts looks like

import { mysqlTable, mysqlSchema, AnyMySqlColumn, primaryKey } from "drizzle-orm/mysql-core"
import { sql } from "drizzle-orm"

export const testTable = mysqlTable("test_table", {
	id: int("id").autoincrement().notNull(),
	// Warning: Can't parse float(8,2) from database
	// float(8,2)Type: float(8,2)("test_float"),
},
(table) => {
	return {
		testTableId: primaryKey(table.id),
	}
});

Here’s my actual MySQL schema:

CREATE TABLE `test_table` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `test_float` float(8,2) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Expected behavior

I expect the output to looks something like this:

export const testTable = mysqlTable("test_table", {
	id: int("id").autoincrement().notNull(),
	testFloat: float("test_float", { precision: 8, scale: 2 }),
},
(table) => {
	return {
		testTableId: primaryKey(table.id),
	}
});

Environment & setup

Node v18.12.1 MacOS Ventura 13.4 MySQL 8.0.33

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

I want to attempt this issue