Skip to content

Commit

Permalink
Merge pull request #64 from Giveth/project-import-flag
Browse files Browse the repository at this point in the history
Added import flag to projects
  • Loading branch information
MohammadPCh authored Jun 6, 2024
2 parents 699b8ae + 8133b43 commit 058a791
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions db/migrations/1717657836767-Data.js
Original file line number Diff line number Diff line change
@@ -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"`)
}
}
21 changes: 21 additions & 0 deletions db/migrations/1717658264897-Data.js
Original file line number Diff line number Diff line change
@@ -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"`);
}
};
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions src/controllers/utils/modelHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const getProject = async (
totalFlags: 0,
totalAttests: 0,
lastUpdatedTimestamp: new Date(),
imported: false,
})
);
project = await ctx.store.findOneBy(Project, { id });
Expand Down
2 changes: 2 additions & 0 deletions src/features/import-projects/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const updateOrCreateProject = async (
image: project[imageField],
slug: project[slugField],
lastUpdatedTimestamp: new Date(),
imported: true,
});

await dataSource
Expand All @@ -73,6 +74,7 @@ export const updateOrCreateProject = async (
totalFlags: 0,
totalAttests: 0,
lastUpdatedTimestamp: new Date(),
imported: true,
});

await dataSource
Expand Down
7 changes: 7 additions & 0 deletions src/model/generated/project.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 058a791

Please sign in to comment.