+5
-5
migrations/2025-11-01-114839_posts/up.sql
+5
-5
migrations/2025-11-01-114839_posts/up.sql
···
277
277
-- Configuration:
278
278
-- - All posts (complete + stubs)
279
279
-- - NO retention policy: Full retention for network scale (2B posts)
280
-
-- - Chunk interval: 1 day
281
-
-- - Compression: 12 hours (aggressive)
280
+
-- - Chunk interval: 7 days
281
+
-- - Compression: 14 days
282
282
-- - Expected compression: ~100:1 combined
283
283
--
284
284
-- Storage projections at 2B posts with 10% complete, 90% stubs:
···
290
290
-- =============================================================================
291
291
292
292
-- Convert to hypertable using rkey column (integer partitioning on TID values)
293
-
-- TID encoding: 4 hours = 14400 seconds = 14400000000 microseconds << 10 bits = 14745600000000
293
+
-- TID encoding: 7 days = 604800 seconds = 604800000000 microseconds << 10 bits = 619315200000000
294
294
SELECT create_hypertable(
295
295
'posts',
296
-
by_range('rkey', 14745600000000), -- 4 hours in TID units
296
+
by_range('rkey', 619315200000000), -- 7 days in TID units
297
297
migrate_data => true,
298
298
if_not_exists => true
299
299
);
300
300
301
-
COMMENT ON TABLE posts IS 'TimescaleDB hypertable for posts (complete + stubs). Partitioned by rkey with 4-hour chunks. Manual compression. No retention policy (full network scale).';
301
+
COMMENT ON TABLE posts IS 'TimescaleDB hypertable for posts (complete + stubs). Partitioned by rkey with 7-day chunks. Manual compression. No retention policy (full network scale).';
302
302
303
303
-- Enable compression
304
304
ALTER TABLE posts SET (
+5
-5
migrations/2025-11-01-114841_engagement/up.sql
+5
-5
migrations/2025-11-01-114841_engagement/up.sql
···
50
50
COMMENT ON COLUMN post_likes.via_repost_rkey IS 'If liked via repost, repost TID (for notification context)';
51
51
52
52
-- Convert post_likes to TimescaleDB hypertable partitioned by rkey (integer partitioning on TID values)
53
-
-- TID encoding: 4 hours = 14400 seconds = 14400000000 microseconds << 10 bits = 14745600000000
53
+
-- TID encoding: 7 days = 604800 seconds = 604800000000 microseconds << 10 bits = 619315200000000
54
54
SELECT create_hypertable(
55
55
'post_likes',
56
-
by_range('rkey', 14745600000000), -- 4 hours in TID units
56
+
by_range('rkey', 619315200000000), -- 7 days in TID units
57
57
migrate_data => true,
58
58
if_not_exists => true
59
59
);
···
67
67
timescaledb.compress_orderby = 'rkey DESC'
68
68
);
69
69
70
-
-- -- Add aggressive compression policy: compress chunks older than 12 hours
70
+
-- -- Add compression policy: compress chunks older than 14 days
71
71
-- -- This is safe because 99.9% of writes are <5 seconds old
72
72
-- SELECT add_compression_policy(
73
73
-- 'post_likes',
74
-
-- compress_after => INTERVAL '12 hours',
74
+
-- compress_after => INTERVAL '14 days',
75
75
-- if_not_exists => true
76
76
-- );
77
77
···
83
83
-- Allows viewer state queries to skip chunks without the viewer's likes
84
84
SELECT enable_chunk_skipping('post_likes', 'actor_id');
85
85
86
-
COMMENT ON TABLE post_likes IS 'TimescaleDB hypertable for post likes. Partitioned by rkey (timestamp) with 4-hour chunks. Auto-compressed after 12 hours. NO retention policy (full network scale). Chunk skipping enabled on post_actor_id and actor_id.';
86
+
COMMENT ON TABLE post_likes IS 'TimescaleDB hypertable for post likes. Partitioned by rkey (timestamp) with 7-day chunks. Auto-compressed after 14 days. NO retention policy (full network scale). Chunk skipping enabled on post_actor_id and actor_id.';
87
87
88
88
-- =============================================================================
89
89
-- FEEDGEN LIKES (rare, ~0.01% of likes)