moved event_json->>property to separate columns

Signed-off-by: Thibaut CHARLES cromfr@gmail.com
This commit is contained in:
Crom (Thibaut CHARLES) 2018-01-10 14:28:27 +01:00
parent a762aecc62
commit 2c3e55c7d3
No known key found for this signature in database
GPG key ID: 45A3D5F880B9E6D0

View file

@ -40,10 +40,14 @@ CREATE TABLE IF NOT EXISTS syncapi_output_room_events (
id BIGINT PRIMARY KEY DEFAULT nextval('syncapi_stream_id'), id BIGINT PRIMARY KEY DEFAULT nextval('syncapi_stream_id'),
-- The event ID for the event -- The event ID for the event
event_id TEXT NOT NULL, event_id TEXT NOT NULL,
-- The 'room_id' key for the event. TODO Duplicate of (event_json->>'room_id') -- The 'room_id' key for the event.
room_id TEXT NOT NULL, room_id TEXT NOT NULL,
-- The JSON for the event. Stored as JSON -- The 'type' property for the event.
event_json JSON NOT NULL, type TEXT NOT NULL,
-- The 'sender' property for the event.
sender TEXT NOT NULL,
-- The JSON for the event. Stored as TEXT because this should be valid UTF-8.
event_json TEXT NOT NULL,
-- A list of event IDs which represent a delta of added/removed room state. This can be NULL -- A list of event IDs which represent a delta of added/removed room state. This can be NULL
-- if there is no delta. -- if there is no delta.
add_state_ids TEXT[], add_state_ids TEXT[],
@ -55,14 +59,14 @@ CREATE TABLE IF NOT EXISTS syncapi_output_room_events (
CREATE UNIQUE INDEX IF NOT EXISTS syncapi_event_id_idx ON syncapi_output_room_events( CREATE UNIQUE INDEX IF NOT EXISTS syncapi_event_id_idx ON syncapi_output_room_events(
event_id, event_id,
room_id, room_id,
(event_json->>'type'), type,
(event_json->>'sender')); sender);
` `
const insertEventSQL = "" + const insertEventSQL = "" +
"INSERT INTO syncapi_output_room_events (" + "INSERT INTO syncapi_output_room_events (" +
" room_id, event_id, event_json, add_state_ids, remove_state_ids, device_id, transaction_id" + " room_id, event_id, type, sender, event_json, add_state_ids, remove_state_ids, device_id, transaction_id" +
") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id" ") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id"
const selectEventsSQL = "" + const selectEventsSQL = "" +
"SELECT id, event_json FROM syncapi_output_room_events WHERE event_id = ANY($1)" "SELECT id, event_json FROM syncapi_output_room_events WHERE event_id = ANY($1)"
@ -71,10 +75,10 @@ const selectRoomRecentEventsSQL = "" +
"SELECT id, event_json, device_id, transaction_id FROM syncapi_output_room_events" + "SELECT id, event_json, device_id, transaction_id FROM syncapi_output_room_events" +
" WHERE room_id=$1 " + " WHERE room_id=$1 " +
" AND id > $2 AND id <= $3" + " AND id > $2 AND id <= $3" +
" AND ( $4::text[] IS NULL OR (event_json->>'sender') = ANY($4) )" + " AND ( $4::text[] IS NULL OR sender = ANY($4) )" +
" AND ( $5::text[] IS NULL OR NOT((event_json->>'sender') = ANY($5)) )" + " AND ( $5::text[] IS NULL OR NOT(sender = ANY($5)) )" +
" AND ( $6::text[] IS NULL OR (event_json->>'type') = ANY($6) )" + " AND ( $6::text[] IS NULL OR type = ANY($6) )" +
" AND ( $7::text[] IS NULL OR NOT((event_json->>'type') = ANY($7)) )" + " AND ( $7::text[] IS NULL OR NOT(type = ANY($7)) )" +
" ORDER BY id DESC LIMIT $8" " ORDER BY id DESC LIMIT $8"
const selectMaxEventIDSQL = "" + const selectMaxEventIDSQL = "" +
@ -220,6 +224,8 @@ func (s *outputRoomEventsStatements) insertEvent(
ctx, ctx,
event.RoomID(), event.RoomID(),
event.EventID(), event.EventID(),
event.Type(),
event.Sender(),
event.JSON(), event.JSON(),
pq.StringArray(addState), pq.StringArray(addState),
pq.StringArray(removeState), pq.StringArray(removeState),