diff --git a/prisma/migrations/20260209222315/migration.sql b/prisma/migrations/20260210015517_use_current_timestamp_defaults/migration.sql similarity index 60% rename from prisma/migrations/20260209222315/migration.sql rename to prisma/migrations/20260210015517_use_current_timestamp_defaults/migration.sql index b92e911..95c8a2e 100644 --- a/prisma/migrations/20260209222315/migration.sql +++ b/prisma/migrations/20260210015517_use_current_timestamp_defaults/migration.sql @@ -1,15 +1,3 @@ -/* - Warnings: - - - You are about to alter the column `offered_at` on the `bids` table. The data in that column could be lost. The data in that column will be cast from `String` to `DateTime`. - - You are about to alter the column `timestamp` on the `games` table. The data in that column could be lost. The data in that column will be cast from `String` to `DateTime`. - - You are about to alter the column `created_at` on the `logs` table. The data in that column could be lost. The data in that column will be cast from `String` to `DateTime`. - - You are about to alter the column `closing_at` on the `market_offers` table. The data in that column could be lost. The data in that column will be cast from `String` to `DateTime`. - - You are about to alter the column `opening_at` on the `market_offers` table. The data in that column could be lost. The data in that column will be cast from `String` to `DateTime`. - - You are about to alter the column `posted_at` on the `market_offers` table. The data in that column could be lost. The data in that column will be cast from `String` to `DateTime`. - - You are about to alter the column `created_at` on the `transactions` table. The data in that column could be lost. The data in that column will be cast from `String` to `DateTime`. - -*/ -- RedefineTables PRAGMA defer_foreign_keys=ON; PRAGMA foreign_keys=OFF; @@ -18,31 +6,13 @@ CREATE TABLE "new_bids" ( "bidder_id" TEXT NOT NULL, "market_offer_id" TEXT NOT NULL, "offer_amount" INTEGER NOT NULL, - "offered_at" DATETIME DEFAULT CURRENT_TIMESTAMP, + "offered_at" TEXT DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "bids_bidder_id_fkey" FOREIGN KEY ("bidder_id") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT "bids_market_offer_id_fkey" FOREIGN KEY ("market_offer_id") REFERENCES "market_offers" ("id") ON DELETE RESTRICT ON UPDATE CASCADE ); INSERT INTO "new_bids" ("bidder_id", "id", "market_offer_id", "offer_amount", "offered_at") SELECT "bidder_id", "id", "market_offer_id", "offer_amount", "offered_at" FROM "bids"; DROP TABLE "bids"; ALTER TABLE "new_bids" RENAME TO "bids"; -CREATE TABLE "new_games" ( - "id" TEXT NOT NULL PRIMARY KEY, - "p1" TEXT NOT NULL, - "p2" TEXT, - "p1_score" INTEGER, - "p2_score" INTEGER, - "p1_elo" INTEGER, - "p2_elo" INTEGER, - "p1_new_elo" INTEGER, - "p2_new_elo" INTEGER, - "type" TEXT, - "timestamp" DATETIME, - CONSTRAINT "games_p1_fkey" FOREIGN KEY ("p1") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "games_p2_fkey" FOREIGN KEY ("p2") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_games" ("id", "p1", "p1_elo", "p1_new_elo", "p1_score", "p2", "p2_elo", "p2_new_elo", "p2_score", "timestamp", "type") SELECT "id", "p1", "p1_elo", "p1_new_elo", "p1_score", "p2", "p2_elo", "p2_new_elo", "p2_score", "timestamp", "type" FROM "games"; -DROP TABLE "games"; -ALTER TABLE "new_games" RENAME TO "games"; CREATE TABLE "new_logs" ( "id" TEXT NOT NULL PRIMARY KEY, "user_id" TEXT NOT NULL, @@ -50,7 +20,7 @@ CREATE TABLE "new_logs" ( "target_user_id" TEXT, "coins_amount" INTEGER, "user_new_amount" INTEGER, - "created_at" DATETIME DEFAULT CURRENT_TIMESTAMP, + "created_at" TEXT DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "logs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT "logs_target_user_id_fkey" FOREIGN KEY ("target_user_id") REFERENCES "users" ("id") ON DELETE SET NULL ON UPDATE CASCADE ); @@ -65,9 +35,9 @@ CREATE TABLE "new_market_offers" ( "buyout_price" INTEGER, "final_price" INTEGER, "status" TEXT NOT NULL, - "posted_at" DATETIME DEFAULT CURRENT_TIMESTAMP, - "opening_at" DATETIME NOT NULL, - "closing_at" DATETIME NOT NULL, + "posted_at" TEXT DEFAULT CURRENT_TIMESTAMP, + "opening_at" TEXT NOT NULL, + "closing_at" TEXT NOT NULL, "buyer_id" TEXT, CONSTRAINT "market_offers_skin_uuid_fkey" FOREIGN KEY ("skin_uuid") REFERENCES "skins" ("uuid") ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT "market_offers_seller_id_fkey" FOREIGN KEY ("seller_id") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, @@ -86,7 +56,7 @@ CREATE TABLE "new_transactions" ( "customer_email" TEXT, "customer_name" TEXT, "payment_status" TEXT NOT NULL, - "created_at" DATETIME DEFAULT CURRENT_TIMESTAMP, + "created_at" TEXT DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "transactions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE ); INSERT INTO "new_transactions" ("amount_cents", "coins_amount", "created_at", "currency", "customer_email", "customer_name", "id", "payment_status", "session_id", "user_id") SELECT "amount_cents", "coins_amount", "created_at", "currency", "customer_email", "customer_name", "id", "payment_status", "session_id", "user_id" FROM "transactions"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 85229eb..fac087b 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -64,9 +64,9 @@ model MarketOffer { buyoutPrice Int? @map("buyout_price") finalPrice Int? @map("final_price") status String - postedAt DateTime? @default(now()) @map("posted_at") - openingAt DateTime @map("opening_at") - closingAt DateTime @map("closing_at") + postedAt String? @default(dbgenerated("CURRENT_TIMESTAMP")) @map("posted_at") + openingAt String @map("opening_at") + closingAt String @map("closing_at") buyerId String? @map("buyer_id") skin Skin @relation(fields: [skinUuid], references: [uuid]) @@ -82,7 +82,7 @@ model Bid { bidderId String @map("bidder_id") marketOfferId String @map("market_offer_id") offerAmount Int @map("offer_amount") - offeredAt DateTime? @default(now()) @map("offered_at") + offeredAt String? @default(dbgenerated("CURRENT_TIMESTAMP")) @map("offered_at") bidder User @relation(fields: [bidderId], references: [id]) marketOffer MarketOffer @relation(fields: [marketOfferId], references: [id]) @@ -97,7 +97,7 @@ model Log { targetUserId String? @map("target_user_id") coinsAmount Int? @map("coins_amount") userNewAmount Int? @map("user_new_amount") - createdAt DateTime? @default(now()) @map("created_at") + createdAt String? @default(dbgenerated("CURRENT_TIMESTAMP")) @map("created_at") user User @relation("UserLogs", fields: [userId], references: [id]) targetUser User? @relation("TargetUserLogs", fields: [targetUserId], references: [id]) @@ -116,7 +116,7 @@ model Game { p1NewElo Int? @map("p1_new_elo") p2NewElo Int? @map("p2_new_elo") type String? - timestamp DateTime? + timestamp String? player1 User @relation("Player1", fields: [p1], references: [id]) player2 User? @relation("Player2", fields: [p2], references: [id]) @@ -167,7 +167,7 @@ model Transaction { customerEmail String? @map("customer_email") customerName String? @map("customer_name") paymentStatus String @map("payment_status") - createdAt DateTime? @default(now()) @map("created_at") + createdAt String? @default(dbgenerated("CURRENT_TIMESTAMP")) @map("created_at") user User @relation(fields: [userId], references: [id]) diff --git a/src/server/routes/solitaire.js b/src/server/routes/solitaire.js index affcd0a..97a8a55 100644 --- a/src/server/routes/solitaire.js +++ b/src/server/routes/solitaire.js @@ -81,8 +81,8 @@ export function solitaireRoutes(client, io) { router.post("/start/sotd", async (req, res) => { const { userId } = req.body; /*if (!userId || !getUser.get(userId)) { - return res.status(404).json({ error: 'User not found.' }); - }*/ + return res.status(404).json({ error: 'User not found.' }); + }*/ if (activeSolitaireGames[userId]?.isSOTD) { return res.json({ diff --git a/src/services/market.service.js b/src/services/market.service.js index cd2a606..a32e379 100644 --- a/src/services/market.service.js +++ b/src/services/market.service.js @@ -1,7 +1,7 @@ import prisma from "../prisma/client.js"; function toOffer(offer) { - return { ...offer, openingAt: offer.openingAt.getTime(), closingAt: offer.closingAt.getTime() }; + return { ...offer, openingAt: Number(offer.openingAt), closingAt: Number(offer.closingAt) }; } export async function getMarketOffers() { @@ -57,8 +57,8 @@ export async function insertMarketOffer(data) { return prisma.marketOffer.create({ data: { ...data, - openingAt: new Date(data.openingAt), - closingAt: new Date(data.closingAt), + openingAt: String(data.openingAt), + closingAt: String(data.closingAt), }, }); }