-- ---------------------------------------------------------------------------
-- Local dev seed -- a default workspace + source + write key.
-- The plaintext write key for development is: cdp_dev_writekey_1234567890
-- key_hash below is sha256 of that string.
-- ---------------------------------------------------------------------------

INSERT INTO workspaces (id, slug, name, tier)
VALUES ('00000000-0000-0000-0000-000000000001', 'dev', 'Dev Workspace', 'default')
ON CONFLICT (slug) DO NOTHING;

INSERT INTO sources (id, workspace_id, slug, name, kind)
VALUES ('00000000-0000-0000-0000-000000000010',
        '00000000-0000-0000-0000-000000000001',
        'web', 'Dev Web Source', 'web')
ON CONFLICT (workspace_id, slug) DO NOTHING;

INSERT INTO write_keys (id, workspace_id, source_id, key_hash, key_prefix, label)
VALUES ('00000000-0000-0000-0000-000000000100',
        '00000000-0000-0000-0000-000000000001',
        '00000000-0000-0000-0000-000000000010',
        encode(digest('cdp_dev_writekey_1234567890', 'sha256'), 'hex'),
        'cdp_dev_',
        'dev key')
ON CONFLICT (key_hash) DO NOTHING;
