vapor-community / mysql-provider

MySQL provider for the Vapor web framework.
MIT License
30 stars 12 forks source link

addConfigurable #25

Closed tanner0101 closed 7 years ago

tanner0101 commented 7 years ago

Right now the MySQL provider will set the database property on the Droplet when it is added. This makes it difficult to use different database's in different environments. Currently you'd have to do something like

if environment != .testing {
    try addProvider(VaporMySQL.Provider.self)
}

The database instead could be set using a Vapor addConfigurable method.

The code in https://github.com/vapor/mysql-provider/blob/master/Sources/VaporMySQL/Provider.swift#L156 would instead be:

    /// See Vapor.Provider.boot
    public func boot(_ drop: Droplet) {
        addConfigurable(database: database, name: "mysql")
    }

With this change, the mysql database would be used when the database property of fluent.json was equal to "mysql".

Config/production/fluent.json

{
    ...
    "database": "mysql"
    ...
}

Then the testing environment could have something like:

Config/test/fluent.json

{
    ...
    "database": "memory"
    ...
}