-- ============================================================
-- 数据库完全重置脚本（清空所有表和数据，重建结构）
-- 警告：此操作不可逆，所有数据将永久丢失！
-- 执行方式：
--   docker exec -i pharmacopoeia-pg psql -U postgres < database/reset_schema.sql
-- ============================================================

BEGIN;

-- 1. 删除所有旧表（级联删除依赖对象）
DROP TABLE IF EXISTS public.answer_records CASCADE;
DROP TABLE IF EXISTS public.user_progress CASCADE;
DROP TABLE IF EXISTS public.messages CASCADE;
DROP TABLE IF EXISTS public.conversations CASCADE;
DROP TABLE IF EXISTS public.drug_chunks CASCADE;
DROP TABLE IF EXISTS public.questions CASCADE;
DROP TABLE IF EXISTS public.knowledge_points CASCADE;
DROP TABLE IF EXISTS public.drugs CASCADE;
DROP TABLE IF EXISTS public.users CASCADE;

-- 2. 删除序列
DROP SEQUENCE IF EXISTS public.answer_records_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.user_progress_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.messages_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.conversations_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.drug_chunks_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.questions_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.knowledge_points_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.drugs_id_seq CASCADE;
DROP SEQUENCE IF EXISTS public.users_id_seq CASCADE;

COMMIT;

-- 3. 重建（直接执行 schema.sql）
-- docker exec -i pharmacopoeia-pg psql -U postgres < database/schema.sql
