Server Side Swift with Vapor - Part 15: Persisting | Ray Wenderlich

Hi Tim,

many thanks for your fast response and help!

Everything running now :slightly_smiling_face:

1 Like

Following the tutorial until the part where we make changes to package.swift, after trying to vapor xcode -y i get:

Generating Xcode Project [Failed]
error: cyclic dependency declaration found: TILApp → Vapor → TILApp → Vapor
‘TILApp’ /Users/JSH/vapor/TILApp: error: product dependency ‘FluentMySQL’ not found
‘TILApp’ /Users/JSH/vapor/TILApp: error: product dependency ‘Vapor’ not found

Error: Could not generate Xcode project: error: cyclic dependency declaration found: TILApp → Vapor → TILApp → Vapor
‘TILApp’ /Users/JSH/vapor/TILApp: error: product dependency ‘FluentMySQL’ not found
‘TILApp’ /Users/JSH/vapor/TILApp: error: product dependency ‘Vapor’ not found

Any help would be great!

@jjjeeerrr111 can you post your Package.swift?

Here it is:

    // swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "TILApp",
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent-mysql.git", from: "3.0.0-rc"),
        ],
    targets: [
        .target(name: "App", dependencies: ["FluentMySQL", "Vapor"]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App"]),
        ]
)

That looks valid to me! Looks like SPM has got itself confused. In terminal run:

rm -rf .build Package.resolved

and try again

1 Like

That worked! Thank you, can you briefly explain what that command did?

So removing .build removes all the existing artefacts and is the same as a clean. Package.resolved holds a map to all your dependencies - sometimes this can get conflicted to deleting it and trying again can resolve dependency issues.

Hey Tim thanks for the explanation. It seems I spoke to quickly. After running your command the build compiled properly but upon running i now get this error over and over:

    [ INFO ] Migrating 'mysql' database (FluentProvider.swift:28)
Program ended with exit code: 9

Id like to be able to follow along for the rest of the tutorial please help!

Is that from Xcode? Is there anything in the console etc? It should all be fine! It just be a connection issue with the DB if it’s not up and running

I got the same error as jjjeeerrr111 mentioned, below is the full error message.

[ INFO ] Migrating ‘mysql’ database (MigrationConfig.swift:69)
Fatal error: Error raised at top level: :warning: MySQL Error: Full authentication not supported over insecure connections.

  • id: MySQLError.fullAuthRequired

File: /Users/marvinzhan/Desktop/IOSDev/vaporTut/TILApp/.build/checkouts/mysql.git-1890032512239690518/Sources/MySQL/Connection/MySQLConnectionHandler.swift

  • func: handlePacket(ctx:packet:)
  • line: 52
  • column: 158
    : file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1000.0.16.7/src/swift/stdlib/public/core/ErrorType.swift, line 191
    2018-06-18 19:32:11.181766-0400 Run[85764:5076064] Fatal error: Error raised at top level: :warning: MySQL Error: Full authentication not supported over insecure connections.
  • id: MySQLError.fullAuthRequired

File: /Users/marvinzhan/Desktop/IOSDev/vaporTut/TILApp/.build/checkouts/mysql.git-1890032512239690518/Sources/MySQL/Connection/MySQLConnectionHandler.swift

  • func: handlePacket(ctx:packet:)
  • line: 52
  • column: 158
    : file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1000.0.16.7/src/swift/stdlib/public/core/ErrorType.swift, line 191

here is the database config I used

var databases = DatabasesConfig()
let database = MySQLDatabase(config: MySQLDatabaseConfig(hostname: "localhost", username: "til", password: "password", database: "vapor"))
databases.add(database: database, as: .mysql)
services.register(databases)

Wondering what caused the issue, thanks for the great tutorial tho!

@marvinzhan what version of MySQL are you using?

mysql -V
mysql Ver 14.14 Distrib 5.7.21, for osx10.13 (x86_64) using EditLine wrapper

Hmm that’s weird - I’m wondering if the EditLine version is doing something weird with the connection. Have you tried a Docker version?

I had to manually downgrade MySQL from 3.1.0 to 3.0.0 to get it compiling, if anyone is facing compile errors when trying to build FluentMySQL for the first time

Hi @0xtim. Really love the video tutorials so far. I’m having an issue when entering the docker commands from the terminal. After entering the user name and password:

docker exec -it mysql mysql -u til -ppassword

I seem to be getting an access denied message:

ERROR 1045 (28000): Access denied for user 'til'@'localhost' (using password: YES)

The run command that I entered prior to this was the one that you offered to @a_stefka:

docker run --name mysql -e MYSQL_USER=vapor \ -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=vapor \ -p 3306:3306 -d mysql/mysql-server:5.7

Which seems to confirm that the password entered was “password”. Any help on why I’m not able to access the DB with the supplied credentials would be very appreciated. Thank you.

Update: @0xtim Response no longer needed.

After several hours of trouble shooting, a fresh round of sleep, and a couple more hours of trouble shooting/StackOverflowing, I decided to delete and reinstall the docker-desktop app and run the same exact commands, but this time with a different user name and password in the environment variables, while also ensuring to specify version 5.7 of MySQL. It worked like a charm after that, building a container with the proper image and accepting the password and username. The full command that I ran was:

docker run --name mysql -e MYSQL_USER=tilUser -e MYSQL_PASSWORD=aBetterPassword -e MYSQL_DATABASE=vapor -p 3306:3306 -d mysql/mysql-server:5.7

However, after I changed the Package.swift file along with the import Statements throughout the project to reflect FluentMySQL (making sure to follow updated changes) I was getting build errors throughout the project saying that certain modules did not exist. I was already on the most current version of Vapor and I already cleaned out my build folder, but it made no difference.

Then on a StackOverflow post I read that if the Package file is changed that you should run the command:
swift package update
in your terminal to allow the package manager to properly pull the right dependencies. After that, it was smooth persistent sailing from there :+1:. Looking forward to the updated videos.

Thanks!

2 Likes

@enuance Thank you for sharing your solution - much appreciated! :]

1 Like

For whoever else that got [ INFO ] Migrating ‘mysql’ database (MigrationConfig.swift:69)
Fatal error: Error raised at top level: :warning: MySQL Error: Full authentication not supported over insecure connections error, you guys can try edit this configuration code on configure.swift

 /// Register the configured SQLite database to the database config.
var databases = DatabasesConfig()
let dbConfig = MySQLDatabaseConfig(hostname: "localhost", port: 3306, username: "xxx", password: "xxx", database: "Vapor", transport: MySQLTransportConfig.unverifiedTLS)
let database = MySQLDatabase(config: dbConfig)
databases.add(database: database, as: .mysql)
databases.enableLogging(on: .mysql)
services.register(databases)