vapor/fluent-mysql-driver

MariaDB cannot hydrate and/or dehydrate bool values

pikkart opened this issue · 1 comments

It seems that mysql-kit 4.0.0-rc.1.3 is not able to handle boolean values, at least with MariaDB

Environment

  • Docker version 19.03.5, build 633a0ea
  • MariaDB: 10.4.12-MariaDB-1:10.4.12+maria~bioni
  • Database Collation: utf8mb4_bin
  • Database Charset: utf8mb4
  • Package.resolved: Package.resolved.txt

Reproduce by
vapor-beta new testboolval

  1. Extend the ToDo Model from the template with a simple boolean field like this:
    // ... 
    @Field(key: "is_confirmed")
    var isConfirmed: Bool
    
    init() { }

    init(id: UUID? = nil, title: String, isConfirmed: Bool) {
        self.id = id
        self.title = title
        self.isConfirmed = isConfirmed
    }
  1. Adjust the migration accordingly:
struct CreateTodo: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        return database.schema("todos")
            .id()
            .field("title", .string, .required)
            .field("is_confirmed", .bool, .required) // <-- the new boolean field
            .create()
    }
    // ...
}
  1. Executing the migration results in the following table structure:
SET NAMES utf8mb4;

CREATE TABLE `todos` (
  `id` varbinary(16) NOT NULL,
  `title` varchar(255) COLLATE utf8mb4_bin NOT NULL,
  `is_confirmed` bit(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
  1. Create a new migration which tries to create a new ToDo record:
struct CreateRecord: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        return [
            Todo(id: nil, title: "Test", isConfirmed: true)
        ].create(on: database)
    }
   // ....
}

This results in:

[4/4] Linking Run
Migrate Command: Prepare
[ INFO ] query read _fluent_migrations
The following migration(s) will be prepared:
+ CreateRecord on default
Would you like to continue?
y/n> y
[ INFO ] query read _fluent_migrations
[ INFO ] query read _fluent_migrations limits=[count(1)]
[ INFO ] query create todos input=[[id: 88FBFBD9-D170-4051-BE83-20C2BC1B5EAA, title: "Test", is_confirmed: true]]
[ ERROR ] MySQL error: Server error: Column 'is_confirmed' cannot be null
Fatal error: Error raised at top level: MySQL error: Server error: Column 'is_confirmed' cannot be null: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.8.280/swift/stdlib/public/core/ErrorType.swift, line 200
➜  test-migraiton git