-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE TABLE username_history | ||
( | ||
id BIGSERIAL NOT NULL PRIMARY KEY, | ||
user_id BIGINT NOT NULL REFERENCES users (id), | ||
social_provider SOCIAL_PROVIDER NOT NULL, | ||
canonical_username VARCHAR NOT NULL, | ||
created_at TIMESTAMP NOT NULL, | ||
updated_at TIMESTAMP NOT NULL, | ||
UNIQUE (canonical_username, social_provider, user_id) | ||
); | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
DROP TABLE username_history; | ||
-- +goose StatementEnd |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- name: UsernameHistoryNew :exec | ||
INSERT INTO username_history (user_id, social_provider, canonical_username, created_at, updated_at) | ||
VALUES (@user_id, @social_provider, LOWER(@username), @created_at, @updated_at) | ||
ON CONFLICT (canonical_username, social_provider, user_id) DO UPDATE | ||
SET updated_at = excluded.updated_at; | ||
|
||
-- name: UsernameHistoryGetByOldUsername :one | ||
SELECT u.username | ||
FROM username_history uh | ||
JOIN users u | ||
ON uh.user_id = u.id | ||
WHERE uh.canonical_username = LOWER(@username) | ||
AND uh.social_provider = @social_provider | ||
ORDER BY uh.updated_at DESC | ||
LIMIT 1; |