Added the catalogue models and seed to support phase 1 of the POC prototype in the Persistence package.
This commit is contained in:
1 parent
717df5208c
commit
6d7ab4bcba
19 files changed
+1381
-151
No files matched your search
@@ -1,28 +0,0 @@
|
||||
import FluentKit
|
||||
|
||||
/// Creates and drops the `example_records` table backing ``ExampleRecord``.
|
||||
///
|
||||
/// Reference scaffolding paired with ``ExampleRecord``; replace it with the first real migration once a
|
||||
/// domain model is defined. Migrations are append-only in production — add a new migration to alter the
|
||||
/// schema rather than editing one that has already run.
|
||||
struct CreateExampleRecord: AsyncMigration {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
/// Creates the `example_records` table with an `id` primary key and a required `name` column.
|
||||
/// - Parameter database: the database the schema change is applied to.
|
||||
func prepare(on database: Database) async throws {
|
||||
try await database.schema(ExampleRecord.schema)
|
||||
.id()
|
||||
.field("name", .string, .required)
|
||||
.create()
|
||||
}
|
||||
|
||||
/// Drops the `example_records` table, reverting ``prepare(on:)``.
|
||||
/// - Parameter database: the database the schema change is applied to.
|
||||
func revert(on database: Database) async throws {
|
||||
try await database.schema(ExampleRecord.schema)
|
||||
.delete()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import FluentKit
|
||||
|
||||
/// Creates and drops the `listings` table backing ``ListingRecord``.
|
||||
struct CreateListing: AsyncMigration {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
func prepare(on database: Database) async throws {
|
||||
try await database.schema(ListingRecord.schema)
|
||||
.id()
|
||||
.field("shop_id", .uuid, .required, .references(ShopRecord.schema, "id", onDelete: .cascade))
|
||||
.field("slug", .string, .required)
|
||||
.field("title", .string, .required)
|
||||
.field("series_title", .string, .required)
|
||||
.field("issue_label", .string, .required)
|
||||
.field("publisher", .string, .required)
|
||||
.field("year", .int, .required)
|
||||
.field("format", .string, .required)
|
||||
.field("printing", .string, .required)
|
||||
.field("printing_detail", .string, .required)
|
||||
.field("is_first_print", .bool, .required)
|
||||
.field("grader", .string)
|
||||
.field("grade", .double)
|
||||
.field("condition", .string, .required)
|
||||
.field("cert_number", .string)
|
||||
.field("page_quality", .string)
|
||||
.field("key_notes", .string)
|
||||
.field("seller_notes", .string, .required)
|
||||
.field("price_cents", .int, .required)
|
||||
.field("shipping_cents", .int, .required)
|
||||
.field("accepts_offers", .bool, .required)
|
||||
.field("cover_tone", .string, .required)
|
||||
.field("cover_title", .string, .required)
|
||||
.field("cover_imprint", .string, .required)
|
||||
.field("cover_number", .string, .required)
|
||||
.field("listed_at", .datetime, .required)
|
||||
.unique(on: "slug")
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) async throws {
|
||||
try await database.schema(ListingRecord.schema)
|
||||
.delete()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import FluentKit
|
||||
|
||||
/// Creates and drops the `shops` table backing ``ShopRecord``.
|
||||
struct CreateShop: AsyncMigration {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
func prepare(on database: Database) async throws {
|
||||
try await database.schema(ShopRecord.schema)
|
||||
.id()
|
||||
.field("slug", .string, .required)
|
||||
.field("name", .string, .required)
|
||||
.field("city", .string, .required)
|
||||
.field("country", .string, .required)
|
||||
.field("since_year", .int, .required)
|
||||
.field("is_verified", .bool, .required)
|
||||
.field("rating", .double, .required)
|
||||
.field("rated_sales", .int, .required)
|
||||
.field("sold_count", .int, .required)
|
||||
.field("handling_days", .int, .required)
|
||||
.field("ships_note", .string, .required)
|
||||
.field("returns_note", .string, .required)
|
||||
.field("about", .string, .required)
|
||||
.unique(on: "slug")
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) async throws {
|
||||
try await database.schema(ShopRecord.schema)
|
||||
.delete()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import FluentKit
|
||||
|
||||
/// Fills the catalogue with the prototype's demo shops and listings.
|
||||
struct SeedCatalogue: AsyncMigration {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
func prepare(on database: Database) async throws {
|
||||
for shop in Seed.shops {
|
||||
let record = ShopRecord(shop)
|
||||
|
||||
try await record.save(on: database)
|
||||
|
||||
let shopID = try record.requireID()
|
||||
|
||||
for listing in Seed.listings where listing.shop.slug == shop.slug {
|
||||
try await ListingRecord(listing, shopID: shopID).save(on: database)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func revert(on database: Database) async throws {
|
||||
try await ListingRecord.query(on: database).delete()
|
||||
try await ShopRecord.query(on: database).delete()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user