-- Migration: 重命名 BaseModel 使用表的主键列 uid → id
-- 涉及表: users, audit_submissions, notifications, user_checkins, user_tasks
-- 执行前请备份数据库

BEGIN;

-- users 表主键及序列重命名
ALTER TABLE users RENAME COLUMN uid TO id;
ALTER SEQUENCE IF EXISTS users_uid_seq RENAME TO users_id_seq;

-- audit_submissions 表主键及序列重命名
ALTER TABLE audit_submissions RENAME COLUMN uid TO id;
ALTER SEQUENCE IF EXISTS audit_submissions_uid_seq RENAME TO audit_submissions_id_seq;

-- notifications 表主键及序列重命名
ALTER TABLE notifications RENAME COLUMN uid TO id;
ALTER SEQUENCE IF EXISTS notifications_uid_seq RENAME TO notifications_id_seq;

-- user_checkins 表主键及序列重命名
ALTER TABLE user_checkins RENAME COLUMN uid TO id;
ALTER SEQUENCE IF EXISTS user_checkins_uid_seq RENAME TO user_checkins_id_seq;

-- user_tasks 表主键及序列重命名
ALTER TABLE user_tasks RENAME COLUMN uid TO id;
ALTER SEQUENCE IF EXISTS user_tasks_uid_seq RENAME TO user_tasks_id_seq;

COMMIT;
