Add first database version and model
This commit is contained in:
32
Sources/App/Model/Migrations/UserTableMigration.swift
Normal file
32
Sources/App/Model/Migrations/UserTableMigration.swift
Normal 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(()))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user