29 lines
911 B
Swift
29 lines
911 B
Swift
import FluentKit
|
|||
|
|
|
||
|
|
/// Adds an owner to shops and a sold date to listings.
|
||
|
|
///
|
||
|
|
/// Registered ahead of ``SeedCatalogue``, whose models write both columns. The owner carries no foreign key: on a fresh database the
|
||
|
|
/// `users` table does not exist yet at this point.
|
||
|
|
struct AddTradeColumns: AsyncMigration {
|
||
|
|
|
||
|
|
// MARK: Methods
|
||
|
|
|
||
|
|
func prepare(on database: Database) async throws {
|
||
|
|
try await database.schema(ShopRecord.schema)
|
||
|
|
.field("owner_id", .uuid)
|
||
|
|
.update()
|
||
|
|
try await database.schema(ListingRecord.schema)
|
||
|
|
.field("sold_at", .datetime)
|
||
|
|
.update()
|
||
|
|
}
|
||
|
|
|
||
|
|
func revert(on database: Database) async throws {
|
||
|
|
try await database.schema(ListingRecord.schema)
|
||
|
|
.deleteField("sold_at")
|
||
|
|
.update()
|
||
|
|
try await database.schema(ShopRecord.schema)
|
||
|
|
.deleteField("owner_id")
|
||
|
|
.update()
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|