vapor-community / sqlite-driver

SQLite driver for Fluent
MIT License
10 stars 15 forks source link

🐛 Bug - Multiple ADDs not supported by SQLite #18

Closed kgn closed 7 years ago

kgn commented 7 years ago

The below migration that was working in Postgress, but failing in SQLite. @vzsg helped me figure out that the issue is that multiple ADDs are not supported by SQLite.

public struct Employer_AddDefaultContributions: Preparation {
    public static func prepare(_ database: Database) throws {
        try database.modify(Employer.entity) { employer in
            employer.double("default_onetime_contribution", optional: true)
            employer.double("default_monthly_contribution", optional: true)
        }
    }

    public static func revert(_ database: Database) throws { }
}

This results in a cryptic error: prepare("near \",\": syntax error"), caused by the following invalid SQLite query:

ALTER TABLE `employers` ADD `default_onetime_contribution` DOUBLE, ADD `default_monthly_contribution` DOUBLE

This can be worked around by splitting up the modify, but this is non-intuitive and should be fixed IMHO.

public struct Employer_AddDefaultContributions: Preparation {
    public static func prepare(_ database: Database) throws {
        // has to be split up until sqlite bug is fixed
        try database.modify(Employer.entity) { employer in
            employer.double("default_onetime_contribution", optional: true)
        }
        try database.modify(Employer.entity) { employer in
            employer.double("default_monthly_contribution", optional: true)
        }
    }

    public static func revert(_ database: Database) throws { }
}
tanner0101 commented 7 years ago

I put up a PR for this ^