|
| 1 | +\set tenant_id random(1, 20) |
| 2 | +\set user_id (1021 * random(10000, 100000)) |
| 3 | +\set order_id random(100001, 999999999) |
| 4 | +\set log_id random(100001, 999999999) |
| 5 | +\set order_amount random(1, 50000) / 100.0 |
| 6 | + |
| 7 | +-- Upsert a user for this tenant. |
| 8 | +INSERT INTO copy_data.users (id, tenant_id, email, settings) |
| 9 | +VALUES (:user_id, :tenant_id, 'bench_' || :user_id || '@example.com', '{"theme":"dark"}') |
| 10 | +ON CONFLICT (id, tenant_id) DO UPDATE SET settings = EXCLUDED.settings; |
| 11 | + |
| 12 | +-- Read the user back. |
| 13 | +SELECT id, tenant_id, email, created_at FROM copy_data.users |
| 14 | +WHERE id = :user_id AND tenant_id = :tenant_id; |
| 15 | + |
| 16 | +-- Insert an order with an explicit large id. |
| 17 | +INSERT INTO copy_data.orders (id, user_id, tenant_id, amount) |
| 18 | +VALUES (:order_id, :user_id, :tenant_id, :order_amount) |
| 19 | +ON CONFLICT (id) DO NOTHING; |
| 20 | + |
| 21 | +-- Read recent orders for this tenant. |
| 22 | +SELECT id, user_id, amount, created_at FROM copy_data.orders |
| 23 | +WHERE tenant_id = :tenant_id ORDER BY created_at DESC LIMIT 5; |
| 24 | + |
| 25 | +-- Update the user settings. |
| 26 | +UPDATE copy_data.users SET settings = jsonb_set(settings, '{last_bench}', to_jsonb(now()::text)) |
| 27 | +WHERE id = :user_id AND tenant_id = :tenant_id; |
| 28 | + |
| 29 | +-- Log an action with an explicit large id. |
| 30 | +INSERT INTO copy_data.log_actions (id, tenant_id, action) |
| 31 | +VALUES (:log_id, :tenant_id, 'bench') |
| 32 | +ON CONFLICT (id) DO NOTHING; |
| 33 | + |
| 34 | +-- Clean up everything we created. |
| 35 | +DELETE FROM copy_data.orders WHERE id = :order_id; |
| 36 | + |
| 37 | +DELETE FROM copy_data.log_actions WHERE id = :log_id; |
| 38 | + |
| 39 | +DELETE FROM copy_data.users |
| 40 | +WHERE id = :user_id AND tenant_id = :tenant_id AND email = 'bench_' || :user_id || '@example.com'; |
0 commit comments