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

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

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

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

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

-- question_set_items.id (BIGSERIAL)
SELECT setval(
    pg_get_serial_sequence('question_set_items', 'id'),
    COALESCE((SELECT MAX(id) FROM question_set_items), 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
);

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

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

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