Kevin

Results 30 comments of Kevin

Here is a unit test to reproduce this bug @0xTim @marius-se @Joannis Vapor version is 4.65.2 It only affects when `app.testable(method: .running)` and production / development enviroment. ```swift @testable import...

After some research, I sloved this problem by writing raw sql ```swift import Foundation import Fluent import Vapor import SQLKit struct CreateArticleHeadCommit: AsyncMigration { func prepare(on database: Database) async throws...

Here is my new approach @0xTim ```swift struct CreateArticleHeadCommit: AsyncMigration { func prepare(on database: Database) async throws { try await database.schema(ArticleEntry.schema) .field("head_commit_id", .uuid) .foreignKey("head_commit_id", references: ArticleCommitEntry.schema, "id", onDelete: .setNull, name:...

@0xTim just wrote a new unit test to debug `deleteConstraint` ```swift final class DatabaseSQLTests: XCTestCase { func testDatabaseSQLTests() throws { let db = DummyDatabaseForTestSQLSerializer() try db.schema(ArticleEntry.schema) .deleteConstraint(name: "created_head_commit_id") .update().wait() print(db.sqlSerializers)...

According to [MySQL's reference Conditions and Restrictions](https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html) ``` MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table...

I made a breakpoint in [FluentMySQLDatabase#48](https://github.com/vapor/fluent-mysql-driver/blob/main/Sources/FluentMySQLDriver/FluentMySQLDatabase.swift#L48) Looks like it convert deleteConstraint into ``` ALTER TABLE `article_entry` DROP KEY `2e2dd11dd7a4d4a0f5f979267ceaa4c9575eae14` ```

Okey, I find out whats the problem https://github.com/vapor/fluent-kit/blob/9d47c328bf83999968c12a3bc94ead1d706ad4a9/Sources/FluentSQL/SQLSchemaConverter.swift#L280 ```swift public func serialize(to serializer: inout SQLSerializer) { if serializer.dialect.name == "mysql" { serializer.write("KEY ") } else { serializer.write("CONSTRAINT ") } let...

> @0xTim just wrote a new unit test to debug `deleteConstraint` > > ```swift > final class DatabaseSQLTests: XCTestCase { > func testDatabaseSQLTests() throws { > let db = DummyDatabaseForTestSQLSerializer()...

I leave some new invesgation on PR https://github.com/vapor/fluent-kit/pull/492#issuecomment-1063959265 @gwynne I would like to know your oppion.