feat: remove old timestamp field

This commit is contained in:
Vyacheslav Matyukhin 2022-05-26 14:14:49 +04:00
parent 31555615a9
commit ab2efa8a88
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
7 changed files with 21 additions and 30 deletions

View File

@ -0,0 +1,12 @@
/*
Warnings:
- You are about to drop the column `timestamp` on the `history` table. All the data in the column will be lost.
- You are about to drop the column `timestamp` on the `questions` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "history" DROP COLUMN "timestamp";
-- AlterTable
ALTER TABLE "questions" DROP COLUMN "timestamp";

View File

@ -50,7 +50,6 @@ model Question {
// } // }
// ] // ]
options Json options Json
timestamp DateTime @db.Timestamp(6) // deprecated
fetched DateTime @db.Timestamp(6) fetched DateTime @db.Timestamp(6)
firstSeen DateTime @map("first_seen") @db.Timestamp(6) firstSeen DateTime @map("first_seen") @db.Timestamp(6)
@ -79,7 +78,6 @@ model History {
platform String platform String
description String description String
options Json options Json
timestamp DateTime @db.Timestamp(6) // deprecated
fetched DateTime @db.Timestamp(6) fetched DateTime @db.Timestamp(6)
qualityindicators Json qualityindicators Json
extra Json extra Json

View File

@ -57,7 +57,6 @@ async function search(query: string): Promise<AlgoliaQuestion[]> {
return questionToAlgoliaQuestion({ return questionToAlgoliaQuestion({
...q, ...q,
fetched: new Date(), fetched: new Date(),
timestamp: new Date(),
firstSeen: new Date(), firstSeen: new Date(),
}); });
}); });

View File

@ -32,7 +32,6 @@ export type FetchedQuestion = Omit<
| "qualityindicators" | "qualityindicators"
| "fetched" | "fetched"
| "firstSeen" | "firstSeen"
| "timestamp"
| "platform" | "platform"
| "options" | "options"
> & { > & {
@ -83,12 +82,7 @@ export type Platform<ArgNames extends string = ""> = {
// So here we build a new type which should be ok to use both in place of prisma's Question type and as an input to its update or create methods. // So here we build a new type which should be ok to use both in place of prisma's Question type and as an input to its update or create methods.
type PreparedQuestion = Omit< type PreparedQuestion = Omit<
Question, Question,
| "extra" "extra" | "qualityindicators" | "options" | "fetched" | "firstSeen"
| "qualityindicators"
| "options"
| "fetched"
| "firstSeen"
| "timestamp"
> & { > & {
fetched: Date; fetched: Date;
extra: NonNullable<Question["extra"]>; extra: NonNullable<Question["extra"]>;
@ -120,7 +114,6 @@ export const upsertSingleQuestion = async (
create: { create: {
...q, ...q,
firstSeen: new Date(), firstSeen: new Date(),
timestamp: q.fetched, // deprecated
}, },
update: q, update: q,
}); });
@ -183,7 +176,6 @@ export const processPlatform = async <T extends string = "">(
data: createdQuestions.map((q) => ({ data: createdQuestions.map((q) => ({
...q, ...q,
firstSeen: new Date(), firstSeen: new Date(),
timestamp: q.fetched, // deprecated
})), })),
}); });
stats.created = createdQuestions.length; stats.created = createdQuestions.length;
@ -211,7 +203,6 @@ export const processPlatform = async <T extends string = "">(
await prisma.history.createMany({ await prisma.history.createMany({
data: [...createdQuestions, ...updatedQuestions].map((q) => ({ data: [...createdQuestions, ...updatedQuestions].map((q) => ({
...q, ...q,
timestamp: q.fetched, // deprecated
idref: q.id, idref: q.id,
})), })),
}); });

View File

@ -10,13 +10,9 @@ const algoliaAppId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID || "";
const client = algoliasearch(algoliaAppId, cookie); const client = algoliasearch(algoliaAppId, cookie);
const index = client.initIndex("metaforecast"); const index = client.initIndex("metaforecast");
export type AlgoliaQuestion = Omit< export type AlgoliaQuestion = Omit<Question, "fetched" | "firstSeen"> & {
Question, fetched: string;
"fetched" | "firstSeen" | "timestamp" firstSeen: string;
> & {
timestamp?: string; // deprecated
fetched?: string;
firstSeen?: string;
optionsstringforsearch?: string; optionsstringforsearch?: string;
platformLabel: string; platformLabel: string;
objectID: string; objectID: string;
@ -39,7 +35,6 @@ export const questionToAlgoliaQuestion = (
return { return {
...question, ...question,
fetched: question.fetched.toISOString(), fetched: question.fetched.toISOString(),
timestamp: question.timestamp.toISOString(), // deprecated
firstSeen: question.firstSeen.toISOString(), firstSeen: question.firstSeen.toISOString(),
platformLabel: platformNameToLabel(question.platform), platformLabel: platformNameToLabel(question.platform),
objectID: question.id, objectID: question.id,

View File

@ -63,15 +63,8 @@ builder.queryField("searchQuestions", (t) =>
return results.map((q) => ({ return results.map((q) => ({
...q, ...q,
fetched: new Date( fetched: new Date(q.fetched),
q.fetched || q.timestamp || new Date().toISOString() // q.timestamp is deprecated, TODO - just use `q.fetched` firstSeen: new Date(q.firstSeen),
),
timestamp: new Date(
q.fetched || q.timestamp || new Date().toISOString()
),
firstSeen: new Date(
q.firstSeen || new Date().toISOString() // TODO - q.firstSeen is not yet populated in algolia
),
})); }));
}, },
}) })

View File

@ -111,6 +111,7 @@ export default async function searchWithAlgolia({
}, },
], ],
fetched: new Date().toISOString(), fetched: new Date().toISOString(),
firstSeen: new Date().toISOString(),
qualityindicators: { qualityindicators: {
numforecasts: 1, numforecasts: 1,
numforecasters: 1, numforecasters: 1,
@ -131,6 +132,7 @@ export default async function searchWithAlgolia({
description: description:
"Fatal error: Too much recursion. Click to proceed anyways", "Fatal error: Too much recursion. Click to proceed anyways",
fetched: new Date().toISOString(), fetched: new Date().toISOString(),
firstSeen: new Date().toISOString(),
options: [ options: [
{ {
name: "Yes", name: "Yes",
@ -178,6 +180,7 @@ export default async function searchWithAlgolia({
}, },
], ],
fetched: new Date().toISOString(), fetched: new Date().toISOString(),
firstSeen: new Date().toISOString(),
qualityindicators: { qualityindicators: {
numforecasts: 1, numforecasts: 1,
numforecasters: 1, numforecasters: 1,