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
timestamp DateTime @db.Timestamp(6) // deprecated
fetched DateTime @db.Timestamp(6)
firstSeen DateTime @map("first_seen") @db.Timestamp(6)
@ -79,7 +78,6 @@ model History {
platform String
description String
options Json
timestamp DateTime @db.Timestamp(6) // deprecated
fetched DateTime @db.Timestamp(6)
qualityindicators Json
extra Json

View File

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

View File

@ -32,7 +32,6 @@ export type FetchedQuestion = Omit<
| "qualityindicators"
| "fetched"
| "firstSeen"
| "timestamp"
| "platform"
| "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.
type PreparedQuestion = Omit<
Question,
| "extra"
| "qualityindicators"
| "options"
| "fetched"
| "firstSeen"
| "timestamp"
"extra" | "qualityindicators" | "options" | "fetched" | "firstSeen"
> & {
fetched: Date;
extra: NonNullable<Question["extra"]>;
@ -120,7 +114,6 @@ export const upsertSingleQuestion = async (
create: {
...q,
firstSeen: new Date(),
timestamp: q.fetched, // deprecated
},
update: q,
});
@ -183,7 +176,6 @@ export const processPlatform = async <T extends string = "">(
data: createdQuestions.map((q) => ({
...q,
firstSeen: new Date(),
timestamp: q.fetched, // deprecated
})),
});
stats.created = createdQuestions.length;
@ -211,7 +203,6 @@ export const processPlatform = async <T extends string = "">(
await prisma.history.createMany({
data: [...createdQuestions, ...updatedQuestions].map((q) => ({
...q,
timestamp: q.fetched, // deprecated
idref: q.id,
})),
});

View File

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

View File

@ -63,15 +63,8 @@ builder.queryField("searchQuestions", (t) =>
return results.map((q) => ({
...q,
fetched: new Date(
q.fetched || q.timestamp || new Date().toISOString() // q.timestamp is deprecated, TODO - just use `q.fetched`
),
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
),
fetched: new Date(q.fetched),
firstSeen: new Date(q.firstSeen),
}));
},
})

View File

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