Skip to content

Instantly share code, notes, and snippets.

@ivanovaleksey ivanovaleksey/seeds.sql
Last active Apr 3, 2018

Embed
What would you like to do?
signals-rs seeds
-- table room
DELETE FROM room;
INSERT INTO room (id)
SELECT uuid_generate_v4()
FROM
generate_series(1, 3);
-- table room
-- table agent
DELETE FROM agent;
INSERT INTO agent (id)
SELECT uuid_generate_v4()
FROM
generate_series(1, 5);
-- table agent
-- table room_agent
DELETE FROM room_agent;
WITH first_room AS (
SELECT id
FROM room
ORDER BY id
LIMIT 1
),
first_two_agents AS (
SELECT id
FROM agent
ORDER BY id
LIMIT 2
)
INSERT INTO room_agent (agent_id, room_id, label)
SELECT
first_two_agents.id,
first_room.id,
'Room agent I-' || row_number()
OVER ()
FROM first_room, first_two_agents;
WITH second_room AS (
SELECT id
FROM room
ORDER BY id
LIMIT 1
OFFSET 1
),
last_two_agents AS (
SELECT id
FROM agent
ORDER BY id DESC
LIMIT 2
)
INSERT INTO room_agent (agent_id, room_id, label)
SELECT
last_two_agents.id,
second_room.id,
'Room agent II-' || row_number()
OVER ()
FROM second_room, last_two_agents;
WITH last_room AS (
SELECT id
FROM room
ORDER BY id DESC
LIMIT 1
),
first_agent AS (
SELECT id
FROM agent
ORDER BY id
LIMIT 1
)
INSERT INTO room_agent (agent_id, room_id, label)
SELECT
first_agent.id,
last_room.id,
'Room agent III-' || row_number()
OVER ()
FROM last_room, first_agent;
-- table room_agent
-- table track
DELETE FROM track;
INSERT INTO track (owner_id, metadata)
SELECT
agent.id,
json_build_object(
'stream_id',
'Stream ' || row_number()
OVER (),
'track_id',
'Track ' || row_number()
OVER (),
'device',
'Camera',
'kind',
CASE WHEN kind = 1
THEN 'video'
ELSE 'audio' END,
'label',
coalesce(t.label, ''))
FROM generate_series(1, 2) AS kind, agent
LEFT JOIN (SELECT DISTINCT ON (agent_id) room_agent.*
FROM room_agent) AS t
ON agent.id = t.agent_id;
-- table track
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.