Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions drizzle/0019_works_position.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DROP INDEX "works_user_id_created_at_idx";--> statement-breakpoint
ALTER TABLE "works" ADD COLUMN "position" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
-- #66: existing works keep the order they already had. The default of 0 would
-- do that on its own, since created_at still breaks the tie — this makes the
-- column say it rather than leave every row claiming to be first.
UPDATE "works" AS w
SET "position" = ordered.rank
FROM (
SELECT "id",
row_number() OVER (PARTITION BY "user_id" ORDER BY "created_at", "id") - 1 AS rank
FROM "works"
) AS ordered
WHERE w."id" = ordered."id";--> statement-breakpoint
CREATE INDEX "works_user_id_position_idx" ON "works" USING btree ("user_id","position","created_at");
Loading
Loading