Skip to content

Instantly share code, notes, and snippets.

@akatakritos
Last active October 6, 2024 21:46
Show Gist options
  • Save akatakritos/18a05732cabec1ce2c82318249bac6c1 to your computer and use it in GitHub Desktop.
Save akatakritos/18a05732cabec1ce2c82318249bac6c1 to your computer and use it in GitHub Desktop.
Postgres schema migration script for MassTransit transactional outbox tables
-- https://github.com/MassTransit/MassTransit/discussions/4847
CREATE TABLE inbox_state
(
id bigint GENERATED BY DEFAULT AS IDENTITY,
message_id uuid NOT NULL,
consumer_id uuid NOT NULL,
lock_id uuid NOT NULL,
row_version bytea,
received timestamp with time zone NOT NULL,
receive_count integer NOT NULL,
expiration_time timestamp with time zone,
consumed timestamp with time zone,
delivered timestamp with time zone,
last_sequence_number bigint,
CONSTRAINT pk_inbox_state PRIMARY KEY (id),
CONSTRAINT ak_inbox_state_message_id_consumer_id UNIQUE (message_id, consumer_id)
);
CREATE TABLE outbox_message
(
sequence_number bigint GENERATED BY DEFAULT AS IDENTITY,
enqueue_time timestamp with time zone,
sent_time timestamp with time zone NOT NULL,
headers text,
properties text,
inbox_message_id uuid,
inbox_consumer_id uuid,
outbox_id uuid,
message_id uuid NOT NULL,
content_type character varying(256) NOT NULL,
message_type text NOT NULL,
body text NOT NULL,
conversation_id uuid,
correlation_id uuid,
initiator_id uuid,
request_id uuid,
source_address character varying(256),
destination_address character varying(256),
response_address character varying(256),
fault_address character varying(256),
expiration_time timestamp with time zone,
CONSTRAINT pk_outbox_message PRIMARY KEY (sequence_number)
);
CREATE TABLE outbox_state
(
outbox_id uuid NOT NULL,
lock_id uuid NOT NULL,
row_version bytea,
created timestamp with time zone NOT NULL,
delivered timestamp with time zone,
last_sequence_number bigint,
CONSTRAINT pk_outbox_state PRIMARY KEY (outbox_id)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment