-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/separate givback verfied #1770
Merged
Merged
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ead0a31
add isGivbackEligible field
MohammadPCh 3c3697c
add AddIsGivbackEligibleColumnToProject1637168932304
MohammadPCh a79066e
add UpdateIsGivbackEligibleForVerifiedProjects1637168932305 migration
MohammadPCh f407bb1
add migration to rename isProjectVerified to isProjectGivbackEligible
MohammadPCh 36fde9a
change isProjectVerified tp isProjectGivbackEligible
MohammadPCh 58cd942
update octant donation
MohammadPCh 770a02a
add approve project
MohammadPCh 2bb1eda
treat project.verified and project.isGivbackEligible equally on sorting
MohammadPCh 11b163c
remove reset verification status on verify
MohammadPCh 48ffb0a
check isGivbackEligible on create ProjectVerificationForm
MohammadPCh 5510afa
Merge branch 'staging' into feat/separate-givback-verfied
MohammadPCh 631a67d
add ProjectInstantPowerViewV3 migration
MohammadPCh ddf24c7
use verifiedOrIsGivbackEligibleCondition
MohammadPCh a1d0374
Use different materialized view for givback factor
mohammadranjbarz ec34862
Fix build error
mohammadranjbarz ca44ce0
Merge branch 'staging' into feat/separate-givback-verfied
mohammadranjbarz 59ac27e
Fix build error
mohammadranjbarz cf155ac
Merge branch 'staging' into feat/separate-givback-verfied
mohammadranjbarz 13695cd
Fix project query for isGivbackEligible and verified
mohammadranjbarz 948205a
Fix add base token migration
mohammadranjbarz 230b3e9
Fix eslint errors
mohammadranjbarz 7229b67
Fix add base token migration
mohammadranjbarz 291c317
Fix add base token migration
mohammadranjbarz 89e2b20
Fix add base token migration
mohammadranjbarz c73dc41
Fix donation test cases related to isGivbackEligible
mohammadranjbarz fa6caa8
Resolve merge conflicts
mohammadranjbarz ed90916
Fix build error
mohammadranjbarz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
migration/1724060343213-AddIsGivbackEligibleColumnToProject.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; | ||
|
||
export class AddIsGivbackEligibleColumnToProject1637168932304 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Add the new column | ||
await queryRunner.addColumn( | ||
'project', | ||
new TableColumn({ | ||
name: 'isGivbackEligible', | ||
type: 'boolean', | ||
isNullable: false, | ||
default: false, | ||
}), | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
// Drop the isGivbackEligible column | ||
await queryRunner.dropColumn('project', 'isGivbackEligible'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
migration/1724060408379-UpdateIsGivbackEligibleForVerifiedProjects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class UpdateIsGivbackEligibleForVerifiedProjects1637168932305 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Update isGivbackEligible to true for verified projects | ||
await queryRunner.query(` | ||
UPDATE project | ||
SET "isGivbackEligible" = true | ||
WHERE "verified" = true; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
// Revert the update (optional) | ||
await queryRunner.query(` | ||
UPDATE project | ||
SET "isGivbackEligible" = false | ||
WHERE "verified" = true; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class ProjectInstantPowerViewV31724223781248 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP MATERIALIZED VIEW IF EXISTS public.project_instant_power_view; | ||
CREATE MATERIALIZED VIEW IF NOT EXISTS public.project_instant_power_view AS | ||
SELECT | ||
innerview."projectId", | ||
ROUND(CAST(innerview."totalPower" as NUMERIC), 2) as "totalPower", | ||
rank() OVER ( | ||
ORDER BY | ||
innerview."totalPower" DESC | ||
) AS "powerRank" | ||
FROM | ||
( | ||
SELECT | ||
project.id AS "projectId", | ||
CASE | ||
WHEN (project.verified = true OR project."isGivbackEligible" = true) AND project."statusId" = 5 THEN COALESCE(sum(pp."boostedPower"), 0 :: double precision) | ||
ELSE 0 :: double precision | ||
END AS "totalPower" | ||
FROM | ||
project | ||
LEFT JOIN ( | ||
SELECT | ||
"powerBoosting"."projectId", | ||
sum("instantPowerBalance".balance * "powerBoosting".percentage :: double precision / 100 :: double precision) AS "boostedPower", | ||
now() AS "updateTime" | ||
FROM | ||
instant_power_balance "instantPowerBalance" | ||
JOIN power_boosting "powerBoosting" ON "powerBoosting"."userId" = "instantPowerBalance"."userId" | ||
GROUP BY | ||
"powerBoosting"."projectId" | ||
) pp ON pp."projectId" = project.id | ||
GROUP BY | ||
project.id | ||
) innerview | ||
ORDER BY | ||
innerview."totalPower" DESC WITH DATA; | ||
`); | ||
|
||
await queryRunner.query(` | ||
CREATE UNIQUE INDEX idx_project_instant_power_view_unique ON public.project_instant_power_view ("projectId"); | ||
`); | ||
|
||
await queryRunner.query(` | ||
CREATE INDEX project_instant_power_view_project_id ON public.project_instant_power_view USING hash ("projectId") TABLESPACE pg_default; | ||
`); | ||
|
||
await queryRunner.query(` | ||
CREATE INDEX project_instant_power_view_total_power ON public.project_instant_power_view USING btree ("totalPower" DESC) TABLESPACE pg_default; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP MATERIALIZED VIEW IF EXISTS public.project_instant_power_view; | ||
DROP INDEX IF EXISTS public.idx_project_instant_power_view_unique; | ||
DROP INDEX IF EXISTS public.project_instant_power_view_project_id; | ||
DROP INDEX IF EXISTS public.project_instant_power_view_total_power; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class ProjectGivbackRankViewV31725260193333 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
` | ||
DROP | ||
MATERIALIZED VIEW IF EXISTS public.project_givback_rank_view; | ||
CREATE MATERIALIZED VIEW IF NOT EXISTS public.project_givback_rank_view AS | ||
SELECT | ||
innerview."projectId", | ||
ROUND(CAST(innerview."totalPower" as NUMERIC), 2) as "totalPower", | ||
rank() OVER ( | ||
ORDER BY | ||
innerview."totalPower" DESC | ||
) AS "powerRank", | ||
"powerRound".round | ||
FROM | ||
( | ||
SELECT | ||
project.id AS "projectId", | ||
CASE project."isGivbackEligible" and project."statusId" = 5 WHEN false THEN 0 :: double precision ELSE COALESCE( | ||
sum(pp."boostedPower"), | ||
0 :: double precision | ||
) END AS "totalPower" | ||
FROM | ||
project project | ||
LEFT JOIN ( | ||
SELECT | ||
"powerRound".round, | ||
"powerBoostingSnapshot"."projectId", | ||
"powerBoostingSnapshot"."userId", | ||
avg( | ||
"powerBalanceSnapshot".balance * "powerBoostingSnapshot".percentage :: double precision / 100 :: double precision | ||
) AS "boostedPower", | ||
now() AS "updateTime" | ||
FROM | ||
power_round "powerRound" | ||
JOIN power_snapshot "powerSnapshot" ON "powerSnapshot"."roundNumber" = "powerRound".round | ||
JOIN power_balance_snapshot "powerBalanceSnapshot" ON "powerBalanceSnapshot"."powerSnapshotId" = "powerSnapshot".id | ||
JOIN power_boosting_snapshot "powerBoostingSnapshot" ON "powerBoostingSnapshot"."powerSnapshotId" = "powerSnapshot".id | ||
AND "powerBoostingSnapshot"."userId" = "powerBalanceSnapshot"."userId" | ||
GROUP BY | ||
"powerRound".round, | ||
"powerBoostingSnapshot"."projectId", | ||
"powerBoostingSnapshot"."userId" | ||
) pp ON pp."projectId" = project.id | ||
GROUP BY | ||
project.id | ||
) innerview, | ||
power_round "powerRound" | ||
ORDER BY | ||
innerview."totalPower" DESC WITH DATA; | ||
CREATE UNIQUE INDEX project_givback_rank_view_project_id_round_unique ON public.project_givback_rank_view ("projectId", "round"); | ||
CREATE INDEX project_givback_rank_view_project_id ON public.project_givback_rank_view USING hash ("projectId") TABLESPACE pg_default; | ||
CREATE INDEX project_givback_rank_view_total_power ON public.project_givback_rank_view USING btree ("totalPower" DESC) TABLESPACE pg_default; | ||
`, | ||
); | ||
} | ||
|
||
public async down(_queryRunner: QueryRunner): Promise<void> { | ||
// | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
migrations/1724061402220-RenameIsProjectVerifiedToIsGivbackEligibleInDonation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class RenameIsProjectVerifiedToIsGivbackEligibleInDonation1637168932306 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE donation | ||
RENAME COLUMN "isProjectVerified" TO "isProjectGivbackEligible"; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE donation | ||
RENAME COLUMN "isProjectGivbackEligible" TO "isProjectVerified"; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
OneToOne, | ||
ViewColumn, | ||
ViewEntity, | ||
JoinColumn, | ||
RelationId, | ||
BaseEntity, | ||
PrimaryColumn, | ||
Column, | ||
Index, | ||
} from 'typeorm'; | ||
import { Field, Float, Int, ObjectType } from 'type-graphql'; | ||
import { Project } from '../entities/project'; | ||
import { ColumnNumericTransformer } from '../utils/entities'; | ||
|
||
@ViewEntity('project_givback_rank_view', { synchronize: false }) | ||
@Index('project_givback_rank_view_project_id_unique', ['projectId', 'round'], { | ||
unique: true, | ||
}) | ||
// It's similar to ProjectPowerView, but with a small difference that it uses a different view | ||
// That just includes project with isGivbackEligible = true | ||
@ObjectType() | ||
export class ProjectGivbackRankView extends BaseEntity { | ||
@Field() | ||
@ViewColumn() | ||
@PrimaryColumn() | ||
@RelationId( | ||
(projectGivbackRankView: ProjectGivbackRankView) => | ||
projectGivbackRankView.project, | ||
) | ||
projectId: number; | ||
|
||
@ViewColumn() | ||
@Field(_type => Float) | ||
@Column('numeric', { | ||
scale: 2, | ||
transformer: new ColumnNumericTransformer(), | ||
}) | ||
totalPower: number; | ||
|
||
@Field(_type => Project) | ||
@OneToOne(_type => Project, project => project.projectPower) | ||
@JoinColumn({ referencedColumnName: 'id' }) | ||
project: Project; | ||
|
||
@ViewColumn() | ||
@Field(_type => Int) | ||
powerRank: number; | ||
|
||
@ViewColumn() | ||
@Field(_type => Int) | ||
round: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct the typographical error in the SQL statement.
The column definition for
"isQR"
incorrectly usesNOT NUL
instead ofNOT NULL
. This will cause the SQL execution to fail due to syntax error.Please apply this correction:
Committable suggestion