Closed mredig closed 2 weeks ago
I tested combining the migrations into a single, creation migration and it worked.
This also worked:
struct CreateUserDBModel_1: AsyncMigration {
func prepare(on database: any Database) async throws {
try await database.schema(User.schema)
.id()
.field(User.Key.firstName, .string, .required)
.field(User.Key.lastName, .string, .required)
.field(User.Key.email, .string, .required)
.field(User.Key.password, .string)
.field(User.Key.isAdmin, .datetime)
.unique(on: User.Key.email)
.create()
}
func revert(on database: any Database) async throws {
try await database.schema(User.schema).delete()
}
}
struct UpdateUserWithLocaleDBModel_5: AsyncMigration {
func prepare(on database: any Database) async throws {
try await database.schema(User.schema)
.field(User.Key.locale, .string)
.update()
try await database.schema(User.schema)
.field(User.Key.timezone, .string)
.update()
}
func revert(on database: any Database) async throws {
try await database.schema(User.schema)
.deleteField(User.Key.locale)
.deleteField(User.Key.timezone)
.update()
}
}
So it looks like it's specifically borked when combining two fields into a single schema builder call. If it wasn't declared earlier, this is with a SQLite db, in case that matters.
Can you enabled SQL Logging and see what it's generating?
This is not a Fluent issue; it's because SQLite's ALTER TABLE
statement is extremely limited and can't change more than one column at a time. Fluent has no way of reporting this, so you just end up with a syntax error when it constructs the syntax that would work with other databases. Your solution here is the correct one for SQLite.
Describe the issue
A migration configuration is causing a crash
Vapor version
hummingbird-main branch 56336d7
Operating system and version
macOS 14.5 (23F79)
Swift version
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Steps to reproduce
I'm not 100% sure this isn't just me holding it wrong, or that this is even the right project (tho I'm more certain of the latter).
To get the error/crash, I have the following migration:
with the following model:
and, for context, here's the initial user creation migration (and the only other user migration):
So, with this setup, I just build and run and the crash happens on startup when running migrations.
Outcome
I get this error and a crash:
2024-10-01T03:19:34-0500 error photoshare : database-id=sqlite error=error: near ",": syntax error migration=photoshare.UpdateUserWithLocaleDBModel_5 [FluentKit] [Migrator] Failed prepare
- I'm thinking the bug is in FluentKit because it's explicitly logging an error and saying as such.Additional notes
M1 - just running debug build in Xcode.