-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: migrate table memo log * chore: update test * chore: add notify top author to discord * chore: add param timeframe * feat: add param timeframe and limit authors to api * chore: add new route for notifying top memo authors in v1 routes * chore: update codeowner
- Loading branch information
Showing
16 changed files
with
350 additions
and
97 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Default reviewers for every PR | ||
* @huynguyenh @namnhce @lmquang | ||
.github/ @huynguyenh @namnhce @lmquang | ||
cmd/ @huynguyenh @namnhce @lmquang | ||
docs/ @huynguyenh @namnhce @lmquang | ||
migrations/ @huynguyenh @namnhce @lmquang | ||
pkg/ @huynguyenh @namnhce @lmquang | ||
* @huynguyenh @lmquang | ||
.github/ @huynguyenh @lmquang | ||
cmd/ @huynguyenh @lmquang | ||
docs/ @huynguyenh @lmquang | ||
migrations/ @huynguyenh @lmquang | ||
pkg/ @huynguyenh @lmquang |
56 changes: 56 additions & 0 deletions
56
migrations/schemas/20241220064435-merge_memo_authors_to_memo_logs.sql
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,56 @@ | ||
-- +migrate Up | ||
-- Add JSONB column to store discord account IDs | ||
ALTER TABLE memo_logs | ||
ADD COLUMN discord_account_ids JSONB DEFAULT '[]'::JSONB; | ||
|
||
-- Migrate data from memo_authors to memo_logs | ||
WITH author_data AS ( | ||
SELECT | ||
memo_log_id, | ||
json_agg(discord_account_id) AS discord_account_ids | ||
FROM memo_authors | ||
GROUP BY memo_log_id | ||
) | ||
UPDATE memo_logs ml | ||
SET discord_account_ids = ad.discord_account_ids | ||
FROM author_data ad | ||
WHERE ml.id = ad.memo_log_id; | ||
|
||
-- Drop the memo_authors table | ||
DROP TABLE memo_authors; | ||
DROP TABLE brainery_logs; | ||
|
||
-- +migrate Down | ||
CREATE TABLE "brainery_logs" ( | ||
"id" uuid NOT NULL DEFAULT uuid(), | ||
"deleted_at" timestamp, | ||
"created_at" timestamp DEFAULT now(), | ||
"updated_at" timestamp DEFAULT now(), | ||
"title" text NOT NULL, | ||
"url" text NOT NULL, | ||
"github_id" text, | ||
"discord_id" text NOT NULL, | ||
"employee_id" uuid, | ||
"tags" jsonb, | ||
"published_at" timestamp NOT NULL, | ||
"reward" numeric, | ||
CONSTRAINT "brainery_logs_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees"("id"), | ||
PRIMARY KEY ("id") | ||
); | ||
CREATE TABLE IF NOT EXISTS memo_authors ( | ||
memo_log_id UUID NOT NULL REFERENCES memo_logs(id), | ||
discord_account_id UUID NOT NULL REFERENCES discord_accounts(id), | ||
created_at TIMESTAMP(6) DEFAULT (now()), | ||
PRIMARY KEY (memo_log_id, discord_account_id) | ||
); | ||
|
||
INSERT INTO memo_authors (memo_log_id, discord_account_id) | ||
SELECT | ||
id AS memo_log_id, | ||
jsonb_array_elements(discord_account_ids)::UUID AS discord_account_id | ||
FROM memo_logs | ||
WHERE jsonb_array_length(discord_account_ids) > 0; | ||
|
||
-- Remove the JSONB column | ||
ALTER TABLE memo_logs | ||
DROP COLUMN discord_account_ids; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package request | ||
|
||
import "errors" | ||
|
||
type TopMemoAuthorsInput struct { | ||
Limit int `json:"limit"` | ||
Days int `json:"days"` | ||
} | ||
|
||
func (i *TopMemoAuthorsInput) Validate() error { | ||
if i.Limit <= 0 { | ||
return errors.New("limit must be greater than 0") | ||
} | ||
if i.Days <= 0 { | ||
return errors.New("days must be greater than 0") | ||
} | ||
return nil | ||
} |
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.