realtime-database
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "realtime-database":https://skillpi.com/zh/skills/deepskill-c93c36a8a1310643d026f68c2c7d47aa93e9786c18e6ef85fd97d4ee3295df7f。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
为实时应用设计数据库模式与查询。适用于提到“聊天数据库”“消息存储”“实时同步”“消息历史”“未读计数”“游标分页”“事件溯源”或“实时数据”的场景,支持消息、活动流、通知与协作类应用的高效分页与同步的数据库模式设计。有关 WebSocket 传输,请参见 websocket-builder。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 实测状态
- 未测试
文件浏览
Frontmatter
name: realtime-database
description: >-
When the user needs to design database schemas and queries optimized for
real-time applications. Use when the user mentions "chat database," "message
storage," "real-time sync," "message history," "unread count," "cursor
pagination," "event sourcing," or "live data." Handles schema design for
messaging, activity feeds, notifications, and collaborative apps with
efficient pagination and sync. For WebSocket transport, see websocket-builder.
license: Apache-2.0
compatibility: "PostgreSQL 14+, MySQL 8+, or MongoDB 6+"
metadata:
author: terminal-skills
version: "1.0.0"
category: development
tags: ["database", "real-time", "messaging", "schema-design"]Real-Time Database
Overview
Designs database schemas and query patterns optimized for real-time applications — chat, activity feeds, notifications, collaborative editing. Focuses on efficient message storage, cursor-based pagination, unread tracking, and sync protocols that minimize data transfer on reconnection.
Instructions
1. Schema Design for Messaging
Core tables for a chat system:
-- Channels (direct messages + groups)
CREATE TABLE channels (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
type VARCHAR(10) NOT NULL CHECK (type IN ('direct', 'group')),
name VARCHAR(100),
created_at TIMESTAMPTZ DEFAULT now()
);
-- Channel membership with read tracking
CREATE TABLE channel_members (
channel_id UUID REFERENCES channels(id),
user_id UUID NOT NULL,
role VARCHAR(20) DEFAULT 'member',
last_read_message_id BIGINT,
joined_at TIMESTAMPTZ DEFAULT now(),
PRIMARY KEY (channel_id, user_id)
);
-- Messages with sequential IDs for ordering
CREATE TABLE messages (
id BIGSERIAL PRIMARY KEY,
channel_id UUID REFERENCES channels(id),
sender_id UUID NOT NULL,
content TEXT NOT NULL,
reply_to_id BIGINT REFERENCES messages(id),
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ,
deleted_at TIMESTAMPTZ
);
CREATE INDEX idx_messages_channel_cursor
ON messages(channel_id, id DESC) WHERE deleted_at IS NULL;
Use BIGSERIAL for message IDs — sequential, sortable, perfect for cursor pagination.
2. Cursor-Based Pagination
Never use OFFSET for message history — it's O(n) and results shift as new messages arrive.
-- Load 50 messages before a cursor (scrolling up)
SELECT id, sender_id, content, created_at
FROM messages
WHERE channel_id = $1 AND id < $2 AND deleted_at IS NULL
ORDER BY id DESC
LIMIT 50;
-- Load messages after a cursor (sync on reconnect)
SELECT id, sender_id, content, created_at
FROM messages
WHERE channel_id = $1 AND id > $2 AND deleted_at IS NULL
ORDER BY id ASC;
Return cursor metadata: { messages: [...], nextCursor: 12345, hasMore: true }
3. Unread Count Tracking
Use the last_read_message_id approach — one integer per user per channel:
-- Get unread count for a user across all channels
SELECT cm.channel_id, COUNT(m.id) AS unread_count
FROM channel_members cm
JOIN messages m ON m.channel_id = cm.channel_id
AND m.id > COALESCE(cm.last_read_message_id, 0)
AND m.deleted_at IS NULL
AND m.sender_id != $1
WHERE cm.user_id = $1
GROUP BY cm.channel_id
HAVING COUNT(m.id) > 0;
-- Mark channel as read
UPDATE channel_members
SET last_read_message_id = $2
WHERE channel_id = $1 AND user_id = $3;
4. Reconnection Sync
When a client reconnects, minimize data transfer:
1. Client sends: { lastMessageIds: { "ch_1": 500, "ch_2": 300 } }
2. Server queries: new messages per channel since those IDs
3. If gap > 200 messages: send summary + latest 50 (client should full-reload)
4. Return: { channels: { "ch_1": { messages: [...], hasMore: false } } }
5. Soft Deletes and Edits
Messages should use soft deletes to maintain thread integrity:
deleted_attimestamp — filter in queries, show "message deleted" in UIupdated_attimestamp — mark edited messages- Keep
reply_to_idreferences valid even after parent is soft-deleted
Examples
Example 1: Chat Schema for SaaS App
Prompt: "Design the database for chat in my project management tool. Direct messages and project channels."
Output: Complete migration with channels, members, messages tables; cursor pagination queries; unread count query; and index strategy. Estimated performance: sub-10ms for message history with 10M+ messages.
Example 2: Activity Feed Schema
Prompt: "I need an activity feed — user actions like 'Alex commented on Task-42'. Need fan-out for team feeds."
Output: Events table with actor/verb/object pattern, fan-out-on-write to per-user feed tables, cursor pagination, and a cleanup job for feeds older than 90 days.
Guidelines
- Use sequential IDs (BIGSERIAL) for cursor pagination — UUIDs can't be sorted by creation order
- Never use OFFSET — cursor pagination is O(1), OFFSET is O(n)
- Track reads per-channel, not per-message — one integer vs. millions of rows
- Index for your access patterns — (channel_id, id DESC) covers 90% of chat queries
- Soft delete messages — hard deletes break reply chains and confuse users
- Partition large tables by channel_id or time range if exceeding 100M rows
- Cache hot channels in Redis — recent messages and member lists
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供实时应用数据库设计,解决消息存储、分页、同步等核心痛点
- 覆盖聊天、活动流、通知等高频场景,具有广泛实用价值
亮点
- 触发词覆盖完整且边界清晰
- 与相关 Skill(websocket-builder)有明确分工说明
待提升项
-
缺少 When to Use 显式章节 原报告严重程度:轻微
虽然在 frontmatter 中有 description,但在 skill_body 中未结构化呈现 When to Use 章节
改进建议:建议在 Overview 后增加显式的 "When to Use" 章节,结构化呈现使用场景
亮点
- Phase/步骤清晰完整
- 提供端到端示例
- frontmatter 完整规范
亮点
- SQL 语法正确,参数使用规范
- 覆盖主要异常处理场景
- 不可逆操作有明确安全条件
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。