-- ======================================================
-- 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
);
