-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate MLS DB To SQLC #380
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
831b4e6
Initial commit
neekolas a99c43b
Set up sqlc
neekolas 86b7131
Initial commit
neekolas 2fa85f6
Set up sqlc
neekolas 1a44dc9
Merge branch 'nm/sqlc-experiment' of github.com:xmtp/xmtp-node-go int…
neekolas 3d192f3
Merge branch 'nm/sqlc-experiment' of github.com:xmtp/xmtp-node-go int…
neekolas 7d9d984
Merge branch 'nm/sqlc-experiment' of github.com:xmtp/xmtp-node-go int…
neekolas 8b434fd
Merge branch 'nm/sqlc-experiment' of github.com:xmtp/xmtp-node-go int…
neekolas 5a658b5
Merge branch 'nm/sqlc-experiment' of github.com:xmtp/xmtp-node-go int…
neekolas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,4 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate |
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,5 @@ | ||
SET statement_timeout = 0; | ||
|
||
--bun:split | ||
|
||
DROP TYPE IF EXISTS inbox_filter; |
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,8 @@ | ||
SET statement_timeout = 0; | ||
|
||
--bun:split | ||
|
||
CREATE TYPE inbox_filter AS ( | ||
inbox_id TEXT, | ||
sequence_id BIGINT | ||
); |
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,78 @@ | ||
-- name: GetAllInboxLogs :many | ||
SELECT * FROM inbox_log | ||
WHERE inbox_id = $1 | ||
ORDER BY sequence_id ASC FOR UPDATE; | ||
|
||
-- name: GetInboxLogFiltered :many | ||
SELECT a.* FROM inbox_log AS a | ||
JOIN ( | ||
SELECT * FROM json_populate_recordset(null::inbox_filter, sqlc.arg(filters)) as b(inbox_id, sequence_id) | ||
) as b on b.inbox_id = a.inbox_id AND a.sequence_id > b.sequence_id | ||
ORDER BY a.sequence_id ASC; | ||
|
||
-- name: InsertInboxLog :one | ||
INSERT INTO inbox_log (inbox_id, server_timestamp_ns, identity_update_proto) | ||
VALUES ($1, $2, $3) | ||
RETURNING sequence_id; | ||
|
||
-- name: CreateInstallation :exec | ||
INSERT INTO installations (id, wallet_address, created_at, updated_at, credential_identity, key_package, expiration) | ||
VALUES ($1, $2, $3, $3, $4, $5, $6); | ||
|
||
-- name: UpdateKeyPackage :execrows | ||
UPDATE installations | ||
SET key_package = @key_package, updated_at = @updated_at, expiration = @expiration | ||
WHERE id = @id; | ||
|
||
-- name: FetchKeyPackages :many | ||
SELECT id, key_package FROM installations | ||
WHERE ID IN (@ids); | ||
|
||
-- name: GetIdentityUpdates :many | ||
SELECT * FROM installations | ||
WHERE wallet_address IN (@wallet_addresses) | ||
AND (created_at > @start_time OR revoked_at > @start_time) | ||
ORDER BY created_at ASC; | ||
|
||
-- name: RevokeInstallation :exec | ||
UPDATE installations | ||
SET revoked_at = @revoked_at | ||
WHERE id = @installation_id | ||
AND revoked_at IS NULL; | ||
|
||
-- name: InsertGroupMessage :one | ||
INSERT INTO group_messages (group_id, data, group_id_data_hash) | ||
VALUES ($1, $2, $3) | ||
RETURNING *; | ||
|
||
-- name: InsertWelcomeMessage :one | ||
INSERT INTO welcome_messages (installation_key, data, installation_key_data_hash, hpke_public_key) | ||
VALUES ($1, $2, $3, $4) | ||
RETURNING *; | ||
|
||
-- name: QueryGroupMessagesAsc :many | ||
SELECT * FROM group_messages | ||
WHERE group_id = @group_id | ||
ORDER BY id ASC | ||
LIMIT @numrows; | ||
|
||
-- name: QueryGroupMessagesDesc :many | ||
SELECT * FROM group_messages | ||
WHERE group_id = @group_id | ||
ORDER BY id DESC | ||
LIMIT @numrows; | ||
|
||
-- name: QueryGroupMessagesWithCursorAsc :many | ||
SELECT * FROM group_messages | ||
WHERE group_id = $1 | ||
AND id > $2 | ||
ORDER BY id ASC | ||
LIMIT $3; | ||
|
||
-- name: QueryGroupMessagesWithCursorDesc :many | ||
SELECT * FROM group_messages | ||
WHERE group_id = $1 | ||
AND id < $2 | ||
ORDER BY id DESC | ||
LIMIT $3; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably the fanciest query we have.
We need to take in an array of (
inbox_id
,sequence_id
) pairs and get the results of each inbox that are greater than thesequence_id
. We are currently doing this in one query per inbox, but this change makes it all happen in one query total by joining against a virtual table.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null::inbox_filter
is a custom SQL data type (not a table) that we decode the JSON serialized filters into