Skip to content

Commit

Permalink
Migrate vm_messages to hypertable (#1149)
Browse files Browse the repository at this point in the history
* Migrate vm_messages to hypertable

* Add column if not exists

* Add comment

* Add comment
  • Loading branch information
birdychang authored Mar 2, 2023
1 parent 5ece2fa commit 68bf175
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions schemas/v1/13_vm_messages_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ func init() {
13,
`
ALTER TABLE {{ .SchemaName | default "public"}}.vm_messages
ADD COLUMN "index" BIGINT NOT NULL,
ADD CONSTRAINT vm_messages_uniq_index UNIQUE (height, state_root, cid, source, index);
ADD COLUMN IF NOT EXISTS "index" BIGINT NOT NULL DEFAULT -1;
-- dropping the default value since it's only needed for existing data to not violate no null constraint
ALTER TABLE {{ .SchemaName | default "public"}}.vm_messages ALTER COLUMN "index" DROP DEFAULT;
COMMENT ON COLUMN {{ .SchemaName | default "public"}}.vm_messages.index IS 'Order in which the message was applied.';
`,
Expand Down
23 changes: 23 additions & 0 deletions schemas/v1/14_vm_messages_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v1

func init() {
patches.Register(
14,
`
{{- if and .SchemaName (ne .SchemaName "public") }}
SET search_path TO {{ .SchemaName }},public;
{{- end }}
-- Convert messages to a hypertable partitioned on height (time)
-- Setting the time interval to 2880 heights so there will be one chunk per day.
SELECT create_hypertable(
'vm_messages',
'height',
chunk_time_interval => 2880,
if_not_exists => TRUE,
migrate_data => TRUE
);
SELECT set_integer_now_func('vm_messages', 'current_height', replace_if_exists => true);
`,
)
}

0 comments on commit 68bf175

Please sign in to comment.