diff --git a/prisma/migrations/20220526101259_no_timestamp_field/migration.sql b/prisma/migrations/20220526101259_no_timestamp_field/migration.sql new file mode 100644 index 0000000..c80c710 --- /dev/null +++ b/prisma/migrations/20220526101259_no_timestamp_field/migration.sql @@ -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"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8020bbe..bc983a7 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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 diff --git a/src/backend/platforms/guesstimate.ts b/src/backend/platforms/guesstimate.ts index 6deda58..c10a3dc 100644 --- a/src/backend/platforms/guesstimate.ts +++ b/src/backend/platforms/guesstimate.ts @@ -57,7 +57,6 @@ async function search(query: string): Promise { return questionToAlgoliaQuestion({ ...q, fetched: new Date(), - timestamp: new Date(), firstSeen: new Date(), }); }); diff --git a/src/backend/platforms/index.ts b/src/backend/platforms/index.ts index 5473c34..bc46403 100644 --- a/src/backend/platforms/index.ts +++ b/src/backend/platforms/index.ts @@ -32,7 +32,6 @@ export type FetchedQuestion = Omit< | "qualityindicators" | "fetched" | "firstSeen" - | "timestamp" | "platform" | "options" > & { @@ -83,12 +82,7 @@ export type Platform = { // 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; @@ -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 ( data: createdQuestions.map((q) => ({ ...q, firstSeen: new Date(), - timestamp: q.fetched, // deprecated })), }); stats.created = createdQuestions.length; @@ -211,7 +203,6 @@ export const processPlatform = async ( await prisma.history.createMany({ data: [...createdQuestions, ...updatedQuestions].map((q) => ({ ...q, - timestamp: q.fetched, // deprecated idref: q.id, })), }); diff --git a/src/backend/utils/algolia.ts b/src/backend/utils/algolia.ts index 98f4c45..2c01454 100644 --- a/src/backend/utils/algolia.ts +++ b/src/backend/utils/algolia.ts @@ -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 & { + 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, diff --git a/src/graphql/schema/search.ts b/src/graphql/schema/search.ts index 6d31357..b587118 100644 --- a/src/graphql/schema/search.ts +++ b/src/graphql/schema/search.ts @@ -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), })); }, }) diff --git a/src/web/worker/searchWithAlgolia.ts b/src/web/worker/searchWithAlgolia.ts index 5f273f0..6798f5a 100644 --- a/src/web/worker/searchWithAlgolia.ts +++ b/src/web/worker/searchWithAlgolia.ts @@ -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,