SQL para reset do moodle

SQL para reset do moodle

por kleber galucio -
Número de respostas: 1

Segue abaixo uma sequência de comandos SQL para resetar o ambiente moodle para um estado de pós-instalado.
Obs: Faça um backup total da Base de dados antes de utilizar os comandos desse arquivo.
- Sugestões/melhorias são bem vindas.

-- RESET MOODLE (DELETE USERS > 100)
-- Testado na versão: 2.9+ (Build: 20150521)
-- Atualizado em 2016-07-06
TRUNCATE TABLE mdl_assign;
TRUNCATE TABLE mdl_assign_grades;
TRUNCATE TABLE mdl_assign_plugin_config;
TRUNCATE TABLE mdl_assign_submission;
TRUNCATE TABLE mdl_assign_user_flags;
TRUNCATE TABLE mdl_assign_user_mapping;
TRUNCATE TABLE mdl_assignfeedback_comments;
TRUNCATE TABLE mdl_assignfeedback_editpdf_annot;
TRUNCATE TABLE mdl_assignfeedback_editpdf_cmnt;
TRUNCATE TABLE mdl_assignfeedback_editpdf_quick;
TRUNCATE TABLE mdl_assignfeedback_file;
TRUNCATE TABLE mdl_assignment;
TRUNCATE TABLE mdl_assignment_submissions;
TRUNCATE TABLE mdl_assignment_upgrade;
TRUNCATE TABLE mdl_assignsubmission_file;
TRUNCATE TABLE mdl_assignsubmission_onlinetext;
TRUNCATE TABLE mdl_backup_controllers;
TRUNCATE TABLE mdl_backup_courses;
TRUNCATE TABLE mdl_backup_logs;
TRUNCATE TABLE mdl_badge;
TRUNCATE TABLE mdl_badge_backpack;
TRUNCATE TABLE mdl_badge_criteria;
TRUNCATE TABLE mdl_badge_criteria_met;
TRUNCATE TABLE mdl_badge_criteria_param;
TRUNCATE TABLE mdl_badge_external;
TRUNCATE TABLE mdl_badge_issued;
TRUNCATE TABLE mdl_badge_manual_award;
TRUNCATE TABLE mdl_block_community;
TRUNCATE TABLE mdl_block_positions;
TRUNCATE TABLE mdl_block_recent_activity;
TRUNCATE TABLE mdl_block_rss_client;
TRUNCATE TABLE mdl_blog_association;
TRUNCATE TABLE mdl_blog_external;
TRUNCATE TABLE mdl_book;
TRUNCATE TABLE mdl_book_chapters;
TRUNCATE TABLE mdl_cache_filters;
TRUNCATE TABLE mdl_chat;
TRUNCATE TABLE mdl_chat_messages;
TRUNCATE TABLE mdl_chat_messages_current;
TRUNCATE TABLE mdl_chat_users;
TRUNCATE TABLE mdl_choice;
TRUNCATE TABLE mdl_choice_answers;
TRUNCATE TABLE mdl_choice_options;
TRUNCATE TABLE mdl_cohort;
TRUNCATE TABLE mdl_cohort_members;
TRUNCATE TABLE mdl_comments;
TRUNCATE TABLE mdl_context_temp;
TRUNCATE TABLE mdl_course_completion_aggr_methd;
TRUNCATE TABLE mdl_course_completion_crit_compl;
TRUNCATE TABLE mdl_course_completion_criteria;
TRUNCATE TABLE mdl_course_completions;
TRUNCATE TABLE mdl_course_modules;
TRUNCATE TABLE mdl_course_modules_completion;
TRUNCATE TABLE mdl_course_published;
TRUNCATE TABLE mdl_course_request;
TRUNCATE TABLE mdl_data;
TRUNCATE TABLE mdl_data_content;
TRUNCATE TABLE mdl_data_fields;
TRUNCATE TABLE mdl_data_records;
TRUNCATE TABLE mdl_enrol;
TRUNCATE TABLE mdl_enrol_flatfile;
TRUNCATE TABLE mdl_enrol_paypal;
TRUNCATE TABLE mdl_event;
TRUNCATE TABLE mdl_event_subscriptions;
TRUNCATE TABLE mdl_events_handlers;
TRUNCATE TABLE mdl_events_queue;
TRUNCATE TABLE mdl_events_queue_handlers;
TRUNCATE TABLE mdl_external_services_users;
TRUNCATE TABLE mdl_external_tokens;
TRUNCATE TABLE mdl_feedback;
TRUNCATE TABLE mdl_feedback_completed;
TRUNCATE TABLE mdl_feedback_completedtmp;
TRUNCATE TABLE mdl_feedback_item;
TRUNCATE TABLE mdl_feedback_sitecourse_map;
TRUNCATE TABLE mdl_feedback_template;
TRUNCATE TABLE mdl_feedback_tracking;
TRUNCATE TABLE mdl_feedback_value;
TRUNCATE TABLE mdl_feedback_valuetmp;
TRUNCATE TABLE mdl_files_reference;
TRUNCATE TABLE mdl_filter_config;
TRUNCATE TABLE mdl_folder;
TRUNCATE TABLE mdl_forum;
TRUNCATE TABLE mdl_forum_digests;
TRUNCATE TABLE mdl_forum_discussion_subs;
-- CASO QUEIRA MANTER OS FORUMS E POSTS
-- TRUNCATE TABLE mdl_forum_discussions;
-- TRUNCATE TABLE mdl_forum_posts;
TRUNCATE TABLE mdl_forum_queue;
TRUNCATE TABLE mdl_forum_read;
TRUNCATE TABLE mdl_forum_subscriptions;
TRUNCATE TABLE mdl_forum_track_prefs;
TRUNCATE TABLE mdl_glossary;
TRUNCATE TABLE mdl_glossary_alias;
TRUNCATE TABLE mdl_glossary_categories;
TRUNCATE TABLE mdl_glossary_entries;
TRUNCATE TABLE mdl_glossary_entries_categories;
TRUNCATE TABLE mdl_grade_categories;
TRUNCATE TABLE mdl_grade_categories_history;
TRUNCATE TABLE mdl_grade_grades;
TRUNCATE TABLE mdl_grade_grades_history;
TRUNCATE TABLE mdl_grade_import_newitem;
TRUNCATE TABLE mdl_grade_import_values;
TRUNCATE TABLE mdl_grade_items;
TRUNCATE TABLE mdl_grade_items_history;
TRUNCATE TABLE mdl_grade_letters;
TRUNCATE TABLE mdl_grade_outcomes;
TRUNCATE TABLE mdl_grade_outcomes_courses;
TRUNCATE TABLE mdl_grade_outcomes_history;
TRUNCATE TABLE mdl_grade_settings;
TRUNCATE TABLE mdl_grading_areas;
TRUNCATE TABLE mdl_grading_definitions;
TRUNCATE TABLE mdl_grading_instances;
TRUNCATE TABLE mdl_gradingform_guide_comments;
TRUNCATE TABLE mdl_gradingform_guide_criteria;
TRUNCATE TABLE mdl_gradingform_guide_fillings;
TRUNCATE TABLE mdl_gradingform_rubric_criteria;
TRUNCATE TABLE mdl_gradingform_rubric_fillings;
TRUNCATE TABLE mdl_gradingform_rubric_levels;
TRUNCATE TABLE mdl_groupings;
TRUNCATE TABLE mdl_groupings_groups;
TRUNCATE TABLE mdl_groups;
TRUNCATE TABLE mdl_groups_members;
TRUNCATE TABLE mdl_imscp;
TRUNCATE TABLE mdl_label;
TRUNCATE TABLE mdl_lesson;
TRUNCATE TABLE mdl_lesson_answers;
TRUNCATE TABLE mdl_lesson_attempts;
TRUNCATE TABLE mdl_lesson_branch;
TRUNCATE TABLE mdl_lesson_grades;
TRUNCATE TABLE mdl_lesson_high_scores;
TRUNCATE TABLE mdl_lesson_overrides;
TRUNCATE TABLE mdl_lesson_pages;
TRUNCATE TABLE mdl_lesson_timer;
TRUNCATE TABLE mdl_lock_db;
TRUNCATE TABLE mdl_log;
TRUNCATE TABLE mdl_log_queries;
TRUNCATE TABLE mdl_lti;
TRUNCATE TABLE mdl_lti_submission;
TRUNCATE TABLE mdl_lti_tool_proxies;
TRUNCATE TABLE mdl_lti_tool_settings;
TRUNCATE TABLE mdl_lti_types;
TRUNCATE TABLE mdl_lti_types_config;
TRUNCATE TABLE mdl_message;
TRUNCATE TABLE mdl_message_airnotifier_devices;
TRUNCATE TABLE mdl_message_contacts;
TRUNCATE TABLE mdl_message_read;
TRUNCATE TABLE mdl_message_working;
TRUNCATE TABLE mdl_messageinbound_datakeys;
TRUNCATE TABLE mdl_messageinbound_messagelist;
TRUNCATE TABLE mdl_mnet_host2service;
TRUNCATE TABLE mdl_mnet_log;
TRUNCATE TABLE mdl_mnet_session;
TRUNCATE TABLE mdl_mnet_sso_access_control;
TRUNCATE TABLE mdl_mnetservice_enrol_courses;
TRUNCATE TABLE mdl_mnetservice_enrol_enrolments;
TRUNCATE TABLE mdl_page;
TRUNCATE TABLE mdl_portfolio_instance;
TRUNCATE TABLE mdl_portfolio_instance_config;
TRUNCATE TABLE mdl_portfolio_instance_user;
TRUNCATE TABLE mdl_portfolio_log;
TRUNCATE TABLE mdl_portfolio_mahara_queue;
TRUNCATE TABLE mdl_portfolio_tempdata;
TRUNCATE TABLE mdl_post;
TRUNCATE TABLE mdl_profiling;
TRUNCATE TABLE mdl_qtype_essay_options;
TRUNCATE TABLE mdl_qtype_match_options;
TRUNCATE TABLE mdl_qtype_match_subquestions;
TRUNCATE TABLE mdl_qtype_multichoice_options;
TRUNCATE TABLE mdl_qtype_randomsamatch_options;
TRUNCATE TABLE mdl_qtype_shortanswer_options;
TRUNCATE TABLE mdl_question;
TRUNCATE TABLE mdl_question_answers;
TRUNCATE TABLE mdl_question_attempt_step_data;
TRUNCATE TABLE mdl_question_attempt_steps;
TRUNCATE TABLE mdl_question_attempts;
TRUNCATE TABLE mdl_question_calculated;
TRUNCATE TABLE mdl_question_calculated_options;
TRUNCATE TABLE mdl_question_categories;
TRUNCATE TABLE mdl_question_dataset_definitions;
TRUNCATE TABLE mdl_question_dataset_items;
TRUNCATE TABLE mdl_question_datasets;
TRUNCATE TABLE mdl_question_hints;
TRUNCATE TABLE mdl_question_multianswer;
TRUNCATE TABLE mdl_question_numerical;
TRUNCATE TABLE mdl_question_numerical_options;
TRUNCATE TABLE mdl_question_numerical_units;
TRUNCATE TABLE mdl_question_response_analysis;
TRUNCATE TABLE mdl_question_response_count;
TRUNCATE TABLE mdl_question_statistics;
TRUNCATE TABLE mdl_question_truefalse;
TRUNCATE TABLE mdl_question_usages;
TRUNCATE TABLE mdl_quiz;
TRUNCATE TABLE mdl_quiz_attempts;
TRUNCATE TABLE mdl_quiz_feedback;
TRUNCATE TABLE mdl_hotpot;
TRUNCATE TABLE mdl_hotpot_attempts;
TRUNCATE TABLE mdl_hotpot_cache;
TRUNCATE TABLE mdl_hotpot_details;
TRUNCATE TABLE mdl_hotpot_questions;
TRUNCATE TABLE mdl_hotpot_responses;
TRUNCATE TABLE mdl_hotpot_strings;

DELETE FROM mdl_user WHERE id > 100;
DELETE FROM mdl_user_preferences WHERE userid > 100;
DELETE FROM mdl_user_info_data WHERE userid > 100;
TRUNCATE mdl_user_password_resets;
TRUNCATE TABLE mdl_user_enrolments;
TRUNCATE TABLE mdl_user_lastaccess;
TRUNCATE TABLE mdl_user_password_resets;

DELETE FROM mdl_editor_atto_autosave WHERE userid >100;

DELETE FROM mdl_files WHERE userid >100;

DELETE FROM mdl_forum_discussions WHERE userid >100;

DELETE FROM mdl_forum_posts WHERE userid >100;

-- FIM DOS COMANDOS.