跑步星球的云端数据存储基于 Supabase(supabase.co)PostgreSQL 数据库。应用通过 Supabase 匿名 Key 直连数据库,没有自建后端服务。客户端使用用户名(username)作为业务主键进行读写。
整包存储:用户的跑步记录、跳绳记录、积分、商城已兑换商品、挑战进度、跑团列表等全部 userData 字段,以单行密文形式保存。
create table run_data ( username text primary key, -- 用户名(业务主键) data text, -- 整包 userData 加密后的密文(见加密方式) updated_at timestamptz -- 最后更新时间 ); alter table run_data disable row level security;
单独存储每个用户的跑团归属信息(团号、加入时间等)。
create table club_data ( username text primary key, data text, updated_at timestamptz ); alter table club_data disable row level security;
跑团内实时聊天消息,明文存储,客户端轮询获取;云端自动清理 7 天前的消息以节省空间并缩小隐私暴露面。
create table club_chat ( id bigint generated always as identity primary key, club_id text, -- 跑团号 username text, -- 发送者 msg text, -- 消息内容 ts bigint -- 时间戳(ms) );
疑似异常运动记录自动上传,由管理员通过 / 驳回;record_id 带唯一约束用于去重。
create table risk_review ( id bigint generated always as identity primary key, username text, record_id bigint unique, -- 关联本地记录ID(唯一去重) distance real, time real, pace real, sport text, risk_reason text, create_time bigint, status integer, -- 审批状态 updated_at bigint ); alter table risk_review disable row level security;
排行榜点赞 / 评论 / 送花数据。该表需在 Supabase 后台手动执行 SQL 创建;未创建时应用自动降级隐藏互动入口,不影响其他功能。
create table rank_interactions ( id bigint generated always as identity primary key, target_user text not null, -- 被互动用户 actor_user text not null, -- 互动用户 type text not null, -- like / comment / flower content text, create_time bigint ); alter table rank_interactions disable row level security;
跨设备双向实时位置共享:分享者与接收者各自 upsert 自己的位置字段,每约 3 秒轮询一次展示双方位置;任一方停止即标记失效。
create table beacon_share ( id text primary key, -- 分享链接ID host_user text, host_lat double precision, host_lon double precision, host_ts bigint, host_active boolean, guest_user text, guest_lat double precision, guest_lon double precision, guest_ts bigint, guest_active boolean, updated_at timestamptz default now() );
_secureEncrypt 进行 XOR + Base64 混淆,密文以 rp2: 前缀标识。username 为键 upsert 到 run_data,实现跨设备覆盖同步。run_data 全表,拉取后解密在本地计算周榜 / 月榜。risk_review 表审批异常记录;club_chat 聊天自动清理 7 天前数据。