Skip to content

Commit

Permalink
Merge pull request #56 from lsst/tickets/DM-43751
Browse files Browse the repository at this point in the history
DM-43751: Change default type mapping for boolean to BOOLEAN for MySQL
  • Loading branch information
JeremyMcCormick committed Apr 18, 2024
2 parents 2c982cf + de6d5e8 commit 00bf779
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/felis/db/sqltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def compile_tinyint(type_: Any, compiler: Any, **kw: Any) -> str:

_TypeMap = Mapping[str, types.TypeEngine | type[types.TypeEngine]]

boolean_map: _TypeMap = {MYSQL: mysql.BIT(1), ORACLE: oracle.NUMBER(1), POSTGRES: postgresql.BOOLEAN()}
boolean_map: _TypeMap = {MYSQL: mysql.BOOLEAN, ORACLE: oracle.NUMBER(1), POSTGRES: postgresql.BOOLEAN()}

byte_map: _TypeMap = {
MYSQL: mysql.TINYINT(),
Expand Down
11 changes: 5 additions & 6 deletions tests/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ def test_mysql_datatypes(self) -> None:
with self.assertRaises(ValidationError):
coldata.col("int", "INTEGER")

with self.assertRaises(ValidationError):
coldata.col("boolean", "BIT(1)")

with self.assertRaises(ValidationError):
coldata.col("float", "FLOAT")

Expand All @@ -82,9 +79,8 @@ def test_mysql_datatypes(self) -> None:
with self.assertRaises(ValidationError):
coldata.col("long", "BIGINT")

# These look like they should be equivalent, but the default is
# actually ``BIT(1)`` for MySQL.
coldata.col("boolean", "BOOLEAN")
with self.assertRaises(ValidationError):
coldata.col("boolean", "BOOLEAN")

with self.assertRaises(ValidationError):
coldata.col("unicode", "NVARCHAR", length=32)
Expand All @@ -102,6 +98,9 @@ def test_mysql_datatypes(self) -> None:
# Same type and length
coldata.col("string", "VARCHAR(128)", length=128)

# Check the old type mapping for MySQL, which is now okay
coldata.col("boolean", "BIT(1)")

# Different types, which is okay
coldata.col("double", "FLOAT")

Expand Down

0 comments on commit 00bf779

Please sign in to comment.