From c38b621bdd6a787bf36b0e42b3b4776714d58b22 Mon Sep 17 00:00:00 2001 From: Michael Simard Date: Mon, 2 Aug 2021 14:48:50 -0500 Subject: [PATCH] prep for statistics table --- .../App/{Models => Content}/AllStats.swift | 0 .../{Models => Content}/DashboardItem.swift | 0 Sources/App/{Models => Content}/Map.swift | 0 .../App/{Models => Content}/MapRecord.swift | 0 .../{Models => Content}/MatchHistory.swift | 0 Sources/App/Migrations/AddCODGame2.swift | 55 ----------- Sources/App/Migrations/CreateStatistics.swift | 92 +++++++++++++++++++ Sources/App/Models/Statistics.swift | 39 ++++++++ Sources/App/configure.swift | 2 +- 9 files changed, 132 insertions(+), 56 deletions(-) rename Sources/App/{Models => Content}/AllStats.swift (100%) rename Sources/App/{Models => Content}/DashboardItem.swift (100%) rename Sources/App/{Models => Content}/Map.swift (100%) rename Sources/App/{Models => Content}/MapRecord.swift (100%) rename Sources/App/{Models => Content}/MatchHistory.swift (100%) delete mode 100644 Sources/App/Migrations/AddCODGame2.swift create mode 100644 Sources/App/Migrations/CreateStatistics.swift create mode 100644 Sources/App/Models/Statistics.swift diff --git a/Sources/App/Models/AllStats.swift b/Sources/App/Content/AllStats.swift similarity index 100% rename from Sources/App/Models/AllStats.swift rename to Sources/App/Content/AllStats.swift diff --git a/Sources/App/Models/DashboardItem.swift b/Sources/App/Content/DashboardItem.swift similarity index 100% rename from Sources/App/Models/DashboardItem.swift rename to Sources/App/Content/DashboardItem.swift diff --git a/Sources/App/Models/Map.swift b/Sources/App/Content/Map.swift similarity index 100% rename from Sources/App/Models/Map.swift rename to Sources/App/Content/Map.swift diff --git a/Sources/App/Models/MapRecord.swift b/Sources/App/Content/MapRecord.swift similarity index 100% rename from Sources/App/Models/MapRecord.swift rename to Sources/App/Content/MapRecord.swift diff --git a/Sources/App/Models/MatchHistory.swift b/Sources/App/Content/MatchHistory.swift similarity index 100% rename from Sources/App/Models/MatchHistory.swift rename to Sources/App/Content/MatchHistory.swift diff --git a/Sources/App/Migrations/AddCODGame2.swift b/Sources/App/Migrations/AddCODGame2.swift deleted file mode 100644 index 805dcef..0000000 --- a/Sources/App/Migrations/AddCODGame2.swift +++ /dev/null @@ -1,55 +0,0 @@ -import Fluent - -//struct CreateMatch: Migration { -// func prepare(on database: Database) -> EventLoopFuture { -// return database.schema("match") -// .id() -// .field("map", .string) -// .field("win", .bool) -// .field("date", .datetime) -// .field("roundsWon", .int) -// .field("roundsLost", .int) -// -// .create() -// } -// -// func revert(on database: Database) -> EventLoopFuture { -// return database.schema("matches").delete() -// } -//} - - -struct AddCasual:Migration{ - - - func prepare(on database: Database) -> EventLoopFuture { - return database.schema("match") - .field("competitive",.bool) - .field("gameMode",.int) - .update() - - } - - func revert(on database: Database) -> EventLoopFuture { - return database.schema("match23es").delete() - } -} - - -//struct AddCODGame2: Migration { -// -// -// func prepare(on database: Database) -> EventLoopFuture { -// return database.schema("match") -// .field("codGame",.string) -// .field("notes",.string) -// .field("players",.string) -// .update() -// -// } -// -// func revert(on database: Database) -> EventLoopFuture { -// return database.schema("match23es").delete() -// } -//} -// diff --git a/Sources/App/Migrations/CreateStatistics.swift b/Sources/App/Migrations/CreateStatistics.swift new file mode 100644 index 0000000..f71d895 --- /dev/null +++ b/Sources/App/Migrations/CreateStatistics.swift @@ -0,0 +1,92 @@ +import Fluent + + +struct CreateStatistics: Migration { + // Prepares the database for storing Galaxy models. + func prepare(on database: Database) -> EventLoopFuture { + database.schema("statistics") + .id() + .field("title", .string) + .field("wins", .int) + .field("losses", .int) + .create() + } + + // Optionally reverts the changes made in the prepare method. + func revert(on database: Database) -> EventLoopFuture { + database.schema("statistics").delete() + } +} + + + +//struct CreateMatch: Migration { +// func prepare(on database: Database) -> EventLoopFuture { +// return database.schema("match") +// .id() +// .field("map", .string) +// .field("win", .bool) +// .field("date", .datetime) +// .field("roundsWon", .int) +// .field("roundsLost", .int) +// +// .create() +// } +// +// func revert(on database: Database) -> EventLoopFuture { +// return database.schema("matches").delete() +// } +//} +// +// +//struct AddStats:Migration{ +// +// +// +// func prepare(on database: Database) -> EventLoopFuture { +// return database.create(Galaxy.self) { builder in +// builder.field(for: \.id, isIdentifier: true) +// builder.field(for: \.name) +// } +// } +// +// func revert(on database: Database) -> EventLoopFuture { +// return database.schema("match23es").delete() +// } +//} +// + +//struct AddCasual:Migration{ +// +// +// func prepare(on database: Database) -> EventLoopFuture { +// return database.schema("match") +// .field("competitive",.bool) +// .field("gameMode",.int) +// .update() +// +// } +// +// func revert(on database: Database) -> EventLoopFuture { +// return database.schema("match23es").delete() +// } +//} + + +//struct AddCODGame2: Migration { +// +// +// func prepare(on database: Database) -> EventLoopFuture { +// return database.schema("match") +// .field("codGame",.string) +// .field("notes",.string) +// .field("players",.string) +// .update() +// +// } +// +// func revert(on database: Database) -> EventLoopFuture { +// return database.schema("match23es").delete() +// } +//} +// diff --git a/Sources/App/Models/Statistics.swift b/Sources/App/Models/Statistics.swift new file mode 100644 index 0000000..1482313 --- /dev/null +++ b/Sources/App/Models/Statistics.swift @@ -0,0 +1,39 @@ +// +// Statistics.swift +// Statistics +// +// Created by Michael Simard on 8/2/21. +// + +import Fluent +import Vapor + +final class Statistics: Model { + // Name of the table or collection. + static let schema = "statistics" + + @ID(key: .id) + var id: UUID? + + @Field(key: "title") + var title: String + + @Field(key: "Wins") + var wins: Int + + @Field(key: "losses") + var losses: Int + + + // Creates a new, empty . + init() { } + + // Creates a new with all properties set. + init(id: UUID? = nil, title: String, wins: Int, losses: Int) { + self.id = id + self.title = title + self.wins = wins + self.losses = losses + + } +} diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index eccb6a3..8edba55 100644 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -25,7 +25,7 @@ public func configure(_ app: Application) throws { ), as: .psql) //app.migrations.add(CreateMatch()) - app.migrations.add(AddCasual()) + app.migrations.add(CreateStatistics())