Add first database version and model

This commit is contained in:
Christoph Hagen
2021-12-22 22:11:37 +01:00
parent fcc1d21e5f
commit 7ac0f29904
4 changed files with 316 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import FluentSQLiteDriver
struct UserTableMigration: Migration {
func prepare(on database: FluentSQLiteDriver.Database) -> EventLoopFuture<Void> {
let one = database.schema(User.schema)
.id()
.field(User.Key.name.key, .string, .required)
.field(User.Key.hash.key, .string, .required)
.field(User.Key.points.key, .int, .required)
.field(User.Key.table.key, .uuid, .references(Table.schema, Table.Key.id.key))
.create()
let two = database.enum(Table.Key.language.rawValue)
.case(SupportedLanguage.german.rawValue)
.case(SupportedLanguage.english.rawValue)
.create()
let three = database.enum(Table.Key.language.rawValue).read().flatMap { lang in
database.schema(Table.schema)
.id()
.field(Table.Key.name.key, .string, .required)
.field(Table.Key.isPublic.key, .bool, .required)
.field(Table.Key.language.key, lang, .required)
.create()
}
return one.and(two).and(three).map { _ in }
}
func revert(on database: FluentSQLiteDriver.Database) -> EventLoopFuture<Void> {
database.eventLoop.makeCompletedFuture(.success(()))
}
}