Skip to content

Commit

Permalink
fix(mpc): bigger type for log pk, avoid duplicate position in queue (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen authored Jan 30, 2025
2 parents b50c797 + 8d24d30 commit 2172b1a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions mpc/coordinator/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,14 @@ CREATE POLICY view_all
true
);

CREATE MATERIALIZED VIEW IF NOT EXISTS current_queue AS
CREATE MATERIALIZED VIEW IF NOT EXISTS public.current_queue AS
(
SELECT *, (SELECT COUNT(*) FROM queue qq
WHERE
NOT EXISTS (SELECT cs.id FROM contribution_status cs WHERE cs.id = qq.id)
AND qq.score > q.score
) + 1 AS position FROM queue q
SELECT *, ROW_NUMBER() OVER(ORDER BY score DESC) AS position
FROM queue q
WHERE
-- Contribution round not started
NOT EXISTS (SELECT cs.id FROM contribution_status cs WHERE cs.id = q.id)
ORDER BY q.score DESC
);

CREATE UNIQUE INDEX idx_current_queue_id ON current_queue(id);
Expand Down Expand Up @@ -662,7 +660,7 @@ ALTER VIEW current_user_state SET (security_invoker = off);
-- Logging --
-----------------
CREATE TABLE log(
id smallserial PRIMARY KEY,
id bigserial PRIMARY KEY,
created_at timestamptz NOT NULL DEFAULT(now()),
message jsonb NOT NULL
);
Expand Down

0 comments on commit 2172b1a

Please sign in to comment.