vapor/fluent-mysql-driver

Prepare response has invalid status...

Closed this issue · 7 comments

Migration fails while using this prepare function:

extension User: Migration {
    static func prepare(on connection: MySQLConnection) -> Future<Void> {
        return MySQLDatabase.create(self, on: connection) { builder in
            try builder.field(type: .varChar(length: 36), for: \.id, isOptional: false, isIdentifier: true)
            try builder.field(type: .varChar(length: 32), for: \.name)
            try builder.field(type: .varChar(length: 255), for: \.email)
...

Connection with the database is established and table fluent is created by default, but table users and others are not. The code was working as it should be in rc.1

I'm having trouble creating this one. Can you double check all of your SPM temporary files are cleared, update, re-gen xcode, and try again?

I did it, and the error persists. If it is of any help, here are my config lines:

    // Register providers first
    try services.register(FluentMySQLProvider())
    // Configure a database
    let databaseConfig = MySQLDatabaseConfig(hostname: configuration.mysqlDatabaseHostname,
                                             port: configuration.mysqlPortNumber,
                                             username: configuration.mysqlUser,
                                             password: configuration.mysqlPassword,
                                             database: configuration.mysqlDatabase)
    services.register(databaseConfig)
// Configure migrations
    var migrationConfig = MigrationConfig()
    migrationConfig.add(model: User.self, database: .mysql)
    migrationConfig.add(model: Notification.self, database: .mysql)
    services.register(migrationConfig)

And here is a complete file - notification.swift

import Crypto
import FluentMySQL
import Foundation
import Random
import Vapor

//  swiftlint:disable identifier_name
final class Notification: Content, MySQLUUIDModel {
    static let idKey = \Notification.id

    var id: UUID?
    var user_id: User.ID
    var notification_type: String
    var unique_link: String
    var link_expiration_tis_1970: Double

    init(user_id: User.ID,
         notification_type: String,
         link_expiration_tis_1970: Double) {
        self.user_id = user_id
        self.notification_type = notification_type

        let data = OSRandom().generateData(count: 32)
        self.unique_link = data.hexString
        
        self.link_expiration_tis_1970 = link_expiration_tis_1970
    }
}

extension Notification: Migration {
    static func prepare(on connection: MySQLConnection) -> Future<Void> {
        return MySQLDatabase.create(self, on: connection) { builder in
            try builder.field(type: .varChar(length: 36), for: \.id, isOptional: false, isIdentifier: true)
            try builder.field(type: .varChar(length: 36), for: \.user_id, isOptional: false, isIdentifier: false)
            try builder.field(type: .varChar(length: 32), for: \.notification_type)
            try builder.field(type: .varChar(length: 64), for: \.unique_link)
            try builder.field(type: .double(), for: \.link_expiration_tis_1970)
        }
    }
}

@Mladen-K can you paste the contents of your Package.resolved as well?

{
  "object": {
    "pins": [
      {
        "package": "Console",
        "repositoryURL": "https://github.com/vapor/console.git",
        "state": {
          "branch": null,
          "revision": "9b219b46ce0248924ed014c23bf8d4df05f2ad80",
          "version": "3.0.0-rc.2.0.1"
        }
      },
      {
        "package": "Core",
        "repositoryURL": "https://github.com/vapor/core.git",
        "state": {
          "branch": null,
          "revision": "b1aef578cc7b55e5eefdb05ed19dfc8ca2452b12",
          "version": "3.0.0-rc.2.1"
        }
      },
      {
        "package": "Crypto",
        "repositoryURL": "https://github.com/vapor/crypto.git",
        "state": {
          "branch": null,
          "revision": "5ea23edc6d3122655daf71756bc769c987a20b29",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "CryptoSwift",
        "repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git",
        "state": {
          "branch": null,
          "revision": "f2ca9c377d4b44596a131e37eeb908221fb6e6be",
          "version": "0.8.3"
        }
      },
      {
        "package": "DatabaseKit",
        "repositoryURL": "https://github.com/vapor/database-kit.git",
        "state": {
          "branch": null,
          "revision": "6565711cc781f4351cade86ab61edd55ecdd8d53",
          "version": "1.0.0-rc.2.1"
        }
      },
      {
        "package": "Engine",
        "repositoryURL": "https://github.com/vapor/engine.git",
        "state": {
          "branch": null,
          "revision": "6a7ca70b6858a0ac8a5c48359c80a3c37f46b47e",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Fluent",
        "repositoryURL": "https://github.com/vapor/fluent.git",
        "state": {
          "branch": null,
          "revision": "0307bdaee347ccb95411b11f0630959fef83c962",
          "version": "3.0.0-rc.2.1.2"
        }
      },
      {
        "package": "FluentMySQL",
        "repositoryURL": "https://github.com/vapor/fluent-mysql.git",
        "state": {
          "branch": null,
          "revision": "6f577efbc369b4c0e54a0edbd400af18aa30844e",
          "version": "3.0.0-rc.2.1"
        }
      },
      {
        "package": "MySQL",
        "repositoryURL": "https://github.com/vapor/mysql.git",
        "state": {
          "branch": null,
          "revision": "29977c5b0a506536710521b990e463dcde43c8e3",
          "version": "3.0.0-rc.2.1"
        }
      },
      {
        "package": "Redis",
        "repositoryURL": "https://github.com/vapor/redis.git",
        "state": {
          "branch": null,
          "revision": "990168b407f45bfc64b0f1b34217c09db23eee15",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Routing",
        "repositoryURL": "https://github.com/vapor/routing.git",
        "state": {
          "branch": null,
          "revision": "2fc1d4de22a54848b35ad17b3e7f7816f19ebf90",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Service",
        "repositoryURL": "https://github.com/vapor/service.git",
        "state": {
          "branch": null,
          "revision": "d2b233ba721b6ed09ae6ba300a1a4e22255f01ae",
          "version": "1.0.0-rc.2.1"
        }
      },
      {
        "package": "TemplateKit",
        "repositoryURL": "https://github.com/vapor/template-kit.git",
        "state": {
          "branch": null,
          "revision": "ef940383716d05ac6e1b0dcb0ba672c7c0f8a718",
          "version": "1.0.0-rc.2.0.1"
        }
      },
      {
        "package": "TokenGenerator",
        "repositoryURL": "git@github.com:Mladen-K/TokenGenerator.git",
        "state": {
          "branch": "master",
          "revision": "533468fb4951636a5530ddc5e351dbabe96993ef",
          "version": null
        }
      },
      {
        "package": "Validation",
        "repositoryURL": "https://github.com/vapor/validation.git",
        "state": {
          "branch": null,
          "revision": "aa12fbde809392ef39ddf046252c94a9fd67c420",
          "version": "2.0.0-rc.2.1"
        }
      },
      {
        "package": "Vapor",
        "repositoryURL": "https://github.com/vapor/vapor.git",
        "state": {
          "branch": null,
          "revision": "dc05167bc1145ce6a29cbb067be4c7b16b7f29d0",
          "version": "3.0.0-rc.2.0.1"
        }
      },
      {
        "package": "swift-nio",
        "repositoryURL": "https://github.com/apple/swift-nio.git",
        "state": {
          "branch": null,
          "revision": "320561f4371d32c74a12158d2e18f220703fe32c",
          "version": "1.2.1"
        }
      },
      {
        "package": "swift-nio-ssl",
        "repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
        "state": {
          "branch": null,
          "revision": "85a55f91bf80afa96889426962f0e0369fae9187",
          "version": "1.0.0"
        }
      },
      {
        "package": "swift-nio-ssl-support",
        "repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
        "state": {
          "branch": null,
          "revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
          "version": "1.0.0"
        }
      },
      {
        "package": "swift-nio-zlib-support",
        "repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
        "state": {
          "branch": null,
          "revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
          "version": "1.0.0"
        }
      }
    ]
  },
  "version": 1
}

Hmm... everything looks correct. I'll try to recreate, thanks!

Didn't find this issue in my search for a solution.
I have provided examples here as well @tanner0101
vapor/vapor#1569

Closing here (vapor/vapor#1569 was closed)