-- ======================================================
-- Reset sequences for LMS tables (PostgreSQL)
-- ======================================================

-- users.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('users', 'id'),
    COALESCE((SELECT MAX(id) FROM users), 1),
    true
);

-- assessment_questions.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('assessment_questions', 'id'),
    COALESCE((SELECT MAX(id) FROM assessment_questions), 1),
    true
);

-- assessment_question_options.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('assessment_question_options', 'id'),
    COALESCE((SELECT MAX(id) FROM assessment_question_options), 1),
    true
);

-- assessment_short_answers.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('assessment_short_answers', 'id'),
    COALESCE((SELECT MAX(id) FROM assessment_short_answers), 1),
    true
);

-- assessment_attempts.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('assessment_attempts', 'id'),
    COALESCE((SELECT MAX(id) FROM assessment_attempts), 1),
    true
);

-- assessment_attempt_questions.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('assessment_attempt_questions', 'id'),
    COALESCE((SELECT MAX(id) FROM assessment_attempt_questions), 1),
    true
);

-- assessment_attempt_answers.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('assessment_attempt_answers', 'id'),
    COALESCE((SELECT MAX(id) FROM assessment_attempt_answers), 1),
    true
);

-- refresh_tokens.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('refresh_tokens', 'id'),
    COALESCE((SELECT MAX(id) FROM refresh_tokens), 1),
    true
);

-- otps.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('otps', 'id'),
    COALESCE((SELECT MAX(id) FROM otps), 1),
    true
);

-- notifications.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('notifications', 'id'),
    COALESCE((SELECT MAX(id) FROM notifications), 1),
    true
);

-- reported_issues.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('reported_issues', 'id'),
    COALESCE((SELECT MAX(id) FROM reported_issues), 1),
    true
);

-- course_categories.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('course_categories', 'id'),
    COALESCE((SELECT MAX(id) FROM course_categories), 1),
    true
);

-- courses.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('courses', 'id'),
    COALESCE((SELECT MAX(id) FROM courses), 1),
    true
);

-- programs.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('programs', 'id'),
    COALESCE((SELECT MAX(id) FROM programs), 1),
    true
);

-- levels.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('levels', 'id'),
    COALESCE((SELECT MAX(id) FROM levels), 1),
    true
);

-- modules.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('modules', 'id'),
    COALESCE((SELECT MAX(id) FROM modules), 1),
    true
);

-- module_videos.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('module_videos', 'id'),
    COALESCE((SELECT MAX(id) FROM module_videos), 1),
    true
);

-- practices.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('practices', 'id'),
    COALESCE((SELECT MAX(id) FROM practices), 1),
    true
);

-- practice_questions.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('practice_questions', 'id'),
    COALESCE((SELECT MAX(id) FROM practice_questions), 1),
    true
);
