-
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
Identity #421
base: main
Are you sure you want to change the base?
Identity #421
Changes from 10 commits
0571e6c
24f04f5
0b9bbf9
ee83663
4a4b1f6
64abfd1
7a435e1
25a37ed
27ef6c8
57ba1c6
af2b611
03008c2
54ed088
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
SET statement_timeout = 0; | ||
SET | ||
statement_timeout = 0; | ||
|
||
--bun:split | ||
CREATE TABLE installations( | ||
id BYTEA PRIMARY KEY, | ||
created_at BIGINT NOT NULL, | ||
updated_at BIGINT NOT NULL, | ||
inbox_id BYTEA NOT NULL, | ||
key_package BYTEA NOT NULL, | ||
expiration BIGINT NOT NULL | ||
CREATE TABLE installations ( | ||
id BYTEA PRIMARY KEY, | ||
created_at BIGINT NOT NULL, | ||
updated_at BIGINT NOT NULL, | ||
inbox_id BYTEA NOT NULL, | ||
key_package BYTEA NOT NULL, | ||
expiration BIGINT NOT NULL | ||
); | ||
|
||
--bun:split | ||
CREATE TABLE group_messages( | ||
id BIGSERIAL PRIMARY KEY, | ||
created_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
group_id BYTEA NOT NULL, | ||
data BYTEA NOT NULL, | ||
group_id_data_hash BYTEA NOT NULL | ||
CREATE TABLE group_messages ( | ||
id BIGSERIAL PRIMARY KEY, | ||
created_at TIMESTAMP NOT NULL DEFAULT NOW (), | ||
group_id BYTEA NOT NULL, | ||
data BYTEA NOT NULL, | ||
group_id_data_hash BYTEA NOT NULL | ||
); | ||
|
||
--bun:split | ||
CREATE INDEX idx_group_messages_group_id_id ON group_messages(group_id, id); | ||
CREATE INDEX idx_group_messages_group_id_id ON group_messages (group_id, id); | ||
|
||
--bun:split | ||
CREATE UNIQUE INDEX idx_group_messages_group_id_data_hash ON group_messages(group_id_data_hash); | ||
CREATE UNIQUE INDEX idx_group_messages_group_id_data_hash ON group_messages (group_id_data_hash); | ||
|
||
--bun:split | ||
CREATE TABLE welcome_messages( | ||
id BIGSERIAL PRIMARY KEY, | ||
created_at TIMESTAMP NOT NULL DEFAULT NOW(), | ||
installation_key BYTEA NOT NULL, | ||
data BYTEA NOT NULL, | ||
hpke_public_key BYTEA NOT NULL, | ||
installation_key_data_hash BYTEA NOT NULL | ||
CREATE TABLE welcome_messages ( | ||
id BIGSERIAL PRIMARY KEY, | ||
created_at TIMESTAMP NOT NULL DEFAULT NOW (), | ||
installation_key BYTEA NOT NULL, | ||
data BYTEA NOT NULL, | ||
hpke_public_key BYTEA NOT NULL, | ||
installation_key_data_hash BYTEA NOT NULL | ||
); | ||
|
||
--bun:split | ||
CREATE INDEX idx_welcome_messages_installation_key_id ON welcome_messages(installation_key, id); | ||
CREATE INDEX idx_welcome_messages_installation_key_id ON welcome_messages (installation_key, id); | ||
|
||
--bun:split | ||
CREATE UNIQUE INDEX idx_welcome_messages_group_key_data_hash ON welcome_messages(installation_key_data_hash); | ||
CREATE UNIQUE INDEX idx_welcome_messages_group_key_data_hash ON welcome_messages (installation_key_data_hash); | ||
|
||
--bun:split | ||
CREATE TABLE inbox_log( | ||
sequence_id BIGSERIAL PRIMARY KEY, | ||
inbox_id BYTEA NOT NULL, | ||
server_timestamp_ns BIGINT NOT NULL, | ||
identity_update_proto BYTEA NOT NULL | ||
CREATE TABLE inbox_log ( | ||
sequence_id BIGSERIAL PRIMARY KEY, | ||
inbox_id BYTEA NOT NULL, | ||
server_timestamp_ns BIGINT NOT NULL, | ||
identity_update_proto BYTEA NOT NULL | ||
); | ||
|
||
--bun:split | ||
CREATE INDEX idx_inbox_log_inbox_id_sequence_id ON inbox_log(inbox_id, sequence_id); | ||
CREATE INDEX idx_inbox_log_inbox_id_sequence_id ON inbox_log (inbox_id, sequence_id); | ||
|
||
--bun:split | ||
CREATE TABLE address_log( | ||
address TEXT NOT NULL, | ||
inbox_id BYTEA NOT NULL, | ||
association_sequence_id BIGINT, | ||
revocation_sequence_id BIGINT | ||
CREATE TABLE address_log ( | ||
address TEXT NOT NULL, | ||
inbox_id BYTEA NOT NULL, | ||
association_sequence_id BIGINT, | ||
revocation_sequence_id BIGINT | ||
); | ||
|
||
--bun:split | ||
CREATE INDEX idx_address_log_address_inbox_id ON address_log(address, inbox_id); | ||
CREATE INDEX idx_address_log_address_inbox_id ON address_log (address, inbox_id); | ||
|
||
--bun:split | ||
CREATE TYPE inbox_filter AS ( | ||
inbox_id TEXT, -- Because this is serialized as JSON, we can't use a BYTEA type | ||
sequence_id BIGINT | ||
inbox_id TEXT, -- Because this is serialized as JSON, we can't use a BYTEA type | ||
sequence_id BIGINT | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SET | ||
statement_timeout = 0; | ||
|
||
DROP INDEX idx_address_log_identifier_inbox_id; | ||
|
||
ALTER TABLE address_log | ||
DROP COLUMN identifier_kind | ||
RENAME COLUMN identifier TO address; | ||
|
||
CREATE INDEX idx_address_log_address_inbox_id ON address_log (address, inbox_id); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
SET | ||
statement_timeout = 0; | ||
|
||
DROP INDEX idx_address_log_address_inbox_id; | ||
|
||
ALTER TABLE address_log | ||
ADD COLUMN identifier_kind INT; | ||
|
||
ALTER TABLE address_log | ||
RENAME COLUMN address TO identifier; | ||
|
||
-- Default all of the existing identifier_kinds to 1 (Ethereum) | ||
UPDATE address_log | ||
SET | ||
identifier_kind = 1; | ||
|
||
ALTER TABLE address_log | ||
ALTER COLUMN identifier_kind | ||
SET | ||
NOT NULL; | ||
|
||
CREATE INDEX idx_address_log_identifier_inbox_id ON address_log (identifier, identifier_kind, inbox_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @neekolas Do you think removing and adding a new index on this table will be an issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's a huge deal because the table is relatively small. But it will block the node from coming up until it's completed. Would be better if we could add the index concurrently, but IIRC we get errors doing that because it happens in a transaction There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CREATE INDEX CONCURRENTLY is what you might want. It takes twice as long, but it does not block concurrent transactions. I don't know whether the newest version of PG still releases the table lock and commits the ongoing transaction implicitly or not. Since its a secondary non-unique index, you don't really care if it does not exist for a period of time. It will just make some queries slower. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my recollection we can't use it in our migrations because the migration runner wraps everything in a transaction, and transactions can't create indexes concurrently. But my knowledge of this codebase is very out of date and maybe the issue is resolved. You can try it. If the issue is still there every test that touches the DB will fail. |
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.
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.
I don't know the internals of PG well enough to remember whether alter table holds an exclusive table lock or not. If an insert happens between the UPDATE and the ALTER, it will have a null column. There has to be a way to do it in one statement...
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.
I would do it like this
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.
You're right, I did write this with the assumption that the migration holds an exclusive lock. I can just be safe and use your approach.