sendou.ink/migrations/041-plus-sixty.js
Kalle 9a126f543d
Plus Voting to 60% criteria + leaderboard access (#1537)
* Update PlusVotingResult

* Logic

* Replace plus tiers

* Testing initial

* Test progress

* Working one test

* Tests

* Schema different file

* Dynamic test

* Fix test util
2023-11-11 12:19:57 +02:00

38 lines
929 B
JavaScript

module.exports.up = function (db) {
db.transaction(() => {
db.prepare(`drop view "PlusVotingResult"`).run();
// same as 000-initial.js except 60% criteria
db.prepare(
/* sql */ `
create view "PlusVotingResult" as
select
"votedId",
"tier",
avg("score") as "score",
avg("score") >= 0.2 as "passedVoting",
"month",
"year",
exists (
select
1
from
"PlusSuggestion"
where
"PlusSuggestion"."month" = "PlusVote"."month"
and "PlusSuggestion"."year" = "PlusVote"."year"
and "PlusSuggestion"."suggestedId" = "PlusVote"."votedId"
and "PlusSuggestion"."tier" = "PlusVote"."tier"
) as "wasSuggested"
from
"PlusVote"
group by
"votedId",
"tier",
"month",
"year";
`,
).run();
})();
};