-- ======================================================
-- Reset sequences for LMS tables
-- ======================================================

SELECT setval(
    pg_get_serial_sequence('users', 'id'),
    COALESCE(MAX(id), 1)
)
FROM users;


SELECT setval(
    pg_get_serial_sequence('courses', 'id'),
    COALESCE(MAX(id), 1)
)
FROM courses;

SELECT setval(
    pg_get_serial_sequence('course_modules', 'id'),
    COALESCE(MAX(id), 1)
)
FROM course_modules;

SELECT setval(
    pg_get_serial_sequence('lessons', 'id'),
    COALESCE(MAX(id), 1)
)
FROM lessons;

SELECT setval(
    pg_get_serial_sequence('enrollments', 'id'),
    COALESCE(MAX(id), 1)
)
FROM enrollments;

SELECT setval(
    pg_get_serial_sequence('assessments', 'id'),
    COALESCE(MAX(id), 1)
)
FROM assessments;

SELECT setval(
    pg_get_serial_sequence('assessment_submissions', 'id'),
    COALESCE(MAX(id), 1)
)
FROM assessment_submissions;

SELECT setval(
    pg_get_serial_sequence('notifications', 'id'),
    COALESCE(MAX(id), 1)
)
FROM notifications;

SELECT setval(
    pg_get_serial_sequence('referral_codes', 'id'),
    COALESCE(MAX(id), 1)
)
FROM referral_codes;

SELECT setval(
    pg_get_serial_sequence('user_referrals', 'id'),
    COALESCE(MAX(id), 1)
)
FROM user_referrals;
