Files
ccn/Packages/Persistence/Sources/Internal/Migrations/CreateUser.swift
T

27 lines
771 B
Swift

import FluentKit
/// Creates and drops the `users` table backing ``UserRecord``, seeded with the prototype's demo accounts.
struct CreateUser: AsyncMigration {
// MARK: Methods
func prepare(on database: Database) async throws {
try await database.schema(UserRecord.schema)
.id()
.field("email", .string, .required)
.field("display_name", .string, .required)
.unique(on: "email")
.create()
for account in Seed.accounts {
try await UserRecord(email: account.email, displayName: account.displayName).save(on: database)
}
}
func revert(on database: Database) async throws {
try await database.schema(UserRecord.schema)
.delete()
}
}