diff --git a/db/migrations/1717657836767-Data.js b/db/migrations/1717657836767-Data.js new file mode 100644 index 0000000..faa0de8 --- /dev/null +++ b/db/migrations/1717657836767-Data.js @@ -0,0 +1,11 @@ +module.exports = class Data1717657836767 { + name = 'Data1717657836767' + + async up(db) { + await db.query(`ALTER TABLE "project" ADD "imported" boolean`) + } + + async down(db) { + await db.query(`ALTER TABLE "project" DROP COLUMN "imported"`) + } +} diff --git a/db/migrations/1717658264897-Data.js b/db/migrations/1717658264897-Data.js new file mode 100644 index 0000000..46d79cd --- /dev/null +++ b/db/migrations/1717658264897-Data.js @@ -0,0 +1,21 @@ +module.exports = class Data1717658264897 { + name = "Data1717658264897"; + + async up(db) { + // fill the new column with default values + await db.query(`UPDATE "project" SET "imported" = false`); + await db.query( + `ALTER TABLE "project" ALTER COLUMN "imported" SET NOT NULL` + ); + await db.query( + `CREATE INDEX "IDX_408502a376cb8a2d0eb8f94ad5" ON "project" ("imported") ` + ); + } + + async down(db) { + await db.query( + `ALTER TABLE "project" ALTER COLUMN "imported" DROP NOT NULL` + ); + await db.query(`DROP INDEX "public"."IDX_408502a376cb8a2d0eb8f94ad5"`); + } +}; diff --git a/schema.graphql b/schema.graphql index d36c109..05212a0 100644 --- a/schema.graphql +++ b/schema.graphql @@ -63,6 +63,8 @@ type Project @entity { slug: String "Image of the project" image: String + "project data is imported from a source or not" + imported: Boolean! @index lastUpdatedTimestamp: DateTime! attests: [ProjectAttestation!]! @derivedFrom(field: "project") attestedOrganisations: [OrganisationProject!]! @derivedFrom(field: "project") diff --git a/src/controllers/utils/modelHelper.ts b/src/controllers/utils/modelHelper.ts index 52c8411..adbeb58 100644 --- a/src/controllers/utils/modelHelper.ts +++ b/src/controllers/utils/modelHelper.ts @@ -70,6 +70,7 @@ export const getProject = async ( totalFlags: 0, totalAttests: 0, lastUpdatedTimestamp: new Date(), + imported: false, }) ); project = await ctx.store.findOneBy(Project, { id }); diff --git a/src/features/import-projects/helpers.ts b/src/features/import-projects/helpers.ts index db652a2..3952d2c 100644 --- a/src/features/import-projects/helpers.ts +++ b/src/features/import-projects/helpers.ts @@ -47,6 +47,7 @@ export const updateOrCreateProject = async ( image: project[imageField], slug: project[slugField], lastUpdatedTimestamp: new Date(), + imported: true, }); await dataSource @@ -73,6 +74,7 @@ export const updateOrCreateProject = async ( totalFlags: 0, totalAttests: 0, lastUpdatedTimestamp: new Date(), + imported: true, }); await dataSource diff --git a/src/model/generated/project.model.ts b/src/model/generated/project.model.ts index bce0129..eae6b27 100644 --- a/src/model/generated/project.model.ts +++ b/src/model/generated/project.model.ts @@ -70,6 +70,13 @@ export class Project { @Column_("text", {nullable: true}) image!: string | undefined | null + /** + * project data is imported from a source or not + */ + @Index_() + @Column_("bool", {nullable: false}) + imported!: boolean + @Column_("timestamp with time zone", {nullable: false}) lastUpdatedTimestamp!: Date