CREATE TABLE auth_group (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(150) NOT NULL
);
CREATE SEQUENCE seq_auth_group START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_auth_group
	BEFORE INSERT OR UPDATE OF id ON auth_group
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_auth_group.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE auth_group_permissions (
  id INTEGER NOT NULL PRIMARY KEY,
  group_id INTEGER NOT NULL,
  permission_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_auth_group_permissions START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_auth_group_permissions
	BEFORE INSERT OR UPDATE OF id ON auth_group_permissions
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_auth_group_permissions.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE auth_permission (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(255) NOT NULL,
  content_type_id INTEGER NOT NULL,
  codename VARCHAR2(100) NOT NULL
);
CREATE SEQUENCE seq_auth_permission START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_auth_permission
	BEFORE INSERT OR UPDATE OF id ON auth_permission
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_auth_permission.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

INSERT INTO auth_permission VALUES ('1', 'Can add permission', '1', 'add_permission');
INSERT INTO auth_permission VALUES ('2', 'Can change permission', '1', 'change_permission');
INSERT INTO auth_permission VALUES ('3', 'Can delete permission', '1', 'delete_permission');
INSERT INTO auth_permission VALUES ('4', 'Can view permission', '1', 'view_permission');
INSERT INTO auth_permission VALUES ('5', 'Can add group', '2', 'add_group');
INSERT INTO auth_permission VALUES ('6', 'Can change group', '2', 'change_group');
INSERT INTO auth_permission VALUES ('7', 'Can delete group', '2', 'delete_group');
INSERT INTO auth_permission VALUES ('8', 'Can view group', '2', 'view_group');
INSERT INTO auth_permission VALUES ('9', 'Can add content type', '3', 'add_contenttype');
INSERT INTO auth_permission VALUES ('10', 'Can change content type', '3', 'change_contenttype');
INSERT INTO auth_permission VALUES ('11', 'Can delete content type', '3', 'delete_contenttype');
INSERT INTO auth_permission VALUES ('12', 'Can view content type', '3', 'view_contenttype');
INSERT INTO auth_permission VALUES ('13', 'Can add session', '4', 'add_session');
INSERT INTO auth_permission VALUES ('14', 'Can change session', '4', 'change_session');
INSERT INTO auth_permission VALUES ('15', 'Can delete session', '4', 'delete_session');
INSERT INTO auth_permission VALUES ('16', 'Can view session', '4', 'view_session');
INSERT INTO auth_permission VALUES ('17', '浏览', '8', 'view_department');
INSERT INTO auth_permission VALUES ('18', '添加', '8', 'add_department');
INSERT INTO auth_permission VALUES ('19', '修改', '8', 'edit_department');
INSERT INTO auth_permission VALUES ('20', '删除', '8', 'delete_department');
INSERT INTO auth_permission VALUES ('21', '浏览', '9', 'view_user');
INSERT INTO auth_permission VALUES ('22', '添加', '9', 'add_user');
INSERT INTO auth_permission VALUES ('23', '修改', '9', 'edit_user');
INSERT INTO auth_permission VALUES ('24', '删除', '9', 'delete_user');

CREATE TABLE base_chapter (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(100) NOT NULL,
  notes VARCHAR2(500) DEFAULT NULL,
  "DELETE" INTEGER NOT NULL,
  subject_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_base_chapter START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_base_chapter
	BEFORE INSERT OR UPDATE OF id ON base_chapter
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_base_chapter.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE base_subject (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(100) NOT NULL,
  notes VARCHAR2(500) DEFAULT NULL,
  "DELETE" INTEGER NOT NULL
);
CREATE SEQUENCE seq_base_subject START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_base_subject
	BEFORE INSERT OR UPDATE OF id ON base_subject
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_base_subject.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE django_content_type (
  id INTEGER NOT NULL PRIMARY KEY,
  app_label VARCHAR2(100) NOT NULL,
  model VARCHAR2(100) NOT NULL
);
CREATE SEQUENCE seq_django_content_type START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_django_content_type
	BEFORE INSERT OR UPDATE OF id ON django_content_type
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_django_content_type.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

INSERT INTO django_content_type VALUES ('2', 'auth', 'group');
INSERT INTO django_content_type VALUES ('1', 'auth', 'permission');
INSERT INTO django_content_type VALUES ('3', 'contenttypes', 'contenttype');
INSERT INTO django_content_type VALUES ('23', 'errorbook', 'errorbook');
INSERT INTO django_content_type VALUES ('12', 'exam', 'exam');
INSERT INTO django_content_type VALUES ('13', 'exam', 'examanswerfilllog');
INSERT INTO django_content_type VALUES ('14', 'exam', 'examanswerlog');
INSERT INTO django_content_type VALUES ('15', 'exam', 'examansweroptionlog');
INSERT INTO django_content_type VALUES ('16', 'exam', 'examlog');
INSERT INTO django_content_type VALUES ('17', 'exampaper', 'exampaper');
INSERT INTO django_content_type VALUES ('18', 'exampaper', 'exampaperdetail');
INSERT INTO django_content_type VALUES ('19', 'examquestion', 'examquestion');
INSERT INTO django_content_type VALUES ('20', 'examquestion', 'examquestionfeedback');
INSERT INTO django_content_type VALUES ('22', 'examquestion', 'examquestionfill');
INSERT INTO django_content_type VALUES ('21', 'examquestion', 'examquestionoption');
INSERT INTO django_content_type VALUES ('7', 'foundation', 'chapter');
INSERT INTO django_content_type VALUES ('6', 'foundation', 'subject');
INSERT INTO django_content_type VALUES ('10', 'knowledge', 'knowledgebase');
INSERT INTO django_content_type VALUES ('11', 'knowledge', 'knowledgebasefeedback');
INSERT INTO django_content_type VALUES ('24', 'practiselog', 'practiseanswerfilllog');
INSERT INTO django_content_type VALUES ('25', 'practiselog', 'practiseanswerlog');
INSERT INTO django_content_type VALUES ('26', 'practiselog', 'practiseansweroptionlog');
INSERT INTO django_content_type VALUES ('27', 'practiselog', 'practiselog');
INSERT INTO django_content_type VALUES ('4', 'sessions', 'session');
INSERT INTO django_content_type VALUES ('8', 'staff', 'department');
INSERT INTO django_content_type VALUES ('9', 'staff', 'user');
INSERT INTO django_content_type VALUES ('5', 'system', 'syslog');

CREATE TABLE django_migrations (
  id INTEGER NOT NULL PRIMARY KEY,
  app VARCHAR2(255) NOT NULL,
  name VARCHAR2(255) NOT NULL,
  applied DATE NOT NULL
);
CREATE SEQUENCE seq_django_migrations START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_django_migrations
	BEFORE INSERT OR UPDATE OF id ON django_migrations
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_django_migrations.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE django_session (
  session_key VARCHAR2(40) NOT NULL,
  session_data CLOB NOT NULL,
  expire_date DATE NOT NULL
);

CREATE TABLE exam (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(200) NOT NULL,
  "TYPE" INTEGER DEFAULT NULL,
  duration INTEGER NOT NULL,
  exam_time DATE NOT NULL,
  exam_end_time DATE DEFAULT NULL,
  "DESC" CLOB,
  examinee_count INTEGER NOT NULL,
  create_time DATE NOT NULL,
  "DELETE" INTEGER NOT NULL,
  create_user_id INTEGER NOT NULL,
  exampaper_id INTEGER DEFAULT NULL,
  subject_id INTEGER DEFAULT NULL
);
CREATE SEQUENCE seq_exam START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam
	BEFORE INSERT OR UPDATE OF id ON exam
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_answer_fill_log (
  id INTEGER NOT NULL PRIMARY KEY,
  content CLOB NOT NULL,
  "ORDER" INTEGER NOT NULL,
  main_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_answer_fill_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_answer_fill_log
	BEFORE INSERT OR UPDATE OF id ON exam_answer_fill_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_answer_fill_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;


CREATE TABLE exam_answer_log (
  id INTEGER NOT NULL PRIMARY KEY,
  status INTEGER NOT NULL,
  detail_id INTEGER NOT NULL,
  main_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_answer_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_answer_log
	BEFORE INSERT OR UPDATE OF id ON exam_answer_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_answer_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_answer_option_log (
  id INTEGER NOT NULL PRIMARY KEY,
  main_id INTEGER NOT NULL,
  option_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_answer_option_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_answer_option_log
	BEFORE INSERT OR UPDATE OF id ON exam_answer_option_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_answer_option_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_log (
  id INTEGER NOT NULL PRIMARY KEY,
  "TYPE" INTEGER NOT NULL,
  scores INTEGER DEFAULT NULL,
  "RANK" INTEGER DEFAULT NULL,
  use_time INTEGER DEFAULT NULL,
  exam_time DATE DEFAULT NULL,
  submit_time DATE DEFAULT NULL,
  single_answer_scores INTEGER NOT NULL,
  multiple_answer_scores INTEGER NOT NULL,
  fill_answer_scores INTEGER NOT NULL,
  judgment_answer_scores INTEGER NOT NULL,
  single_answer_count INTEGER NOT NULL,
  multiple_answer_count INTEGER NOT NULL,
  fill_answer_count INTEGER NOT NULL,
  judgment_answer_count INTEGER NOT NULL,
  is_delete INTEGER NOT NULL,
  exam_id INTEGER DEFAULT NULL,
  exampaper_id INTEGER DEFAULT NULL,
  user_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_log
	BEFORE INSERT OR UPDATE OF id ON exam_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_paper (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(200) NOT NULL,
  "TYPE" INTEGER NOT NULL,
  passline INTEGER NOT NULL,
  "DESC" CLOB,
  single_simple_count INTEGER NOT NULL,
  multiple_simple_count INTEGER NOT NULL,
  fill_simple_count INTEGER NOT NULL,
  judgment_simple_count INTEGER NOT NULL,
  single_mid_count INTEGER NOT NULL,
  multiple_mid_count INTEGER NOT NULL,
  fill_mid_count INTEGER NOT NULL,
  judgment_mid_count INTEGER NOT NULL,
  single_hard_count INTEGER NOT NULL,
  multiple_hard_count INTEGER NOT NULL,
  fill_hard_count INTEGER NOT NULL,
  judgment_hard_count INTEGER NOT NULL,
  single_scores INTEGER NOT NULL,
  multiple_scores INTEGER NOT NULL,
  fill_scores INTEGER NOT NULL,
  judgment_scores INTEGER NOT NULL,
  single_total_count INTEGER NOT NULL,
  multiple_total_count INTEGER NOT NULL,
  fill_total_count INTEGER NOT NULL,
  judgment_total_count INTEGER NOT NULL,
  single_total_scores INTEGER NOT NULL,
  multiple_total_scores INTEGER NOT NULL,
  fill_total_scores INTEGER NOT NULL,
  judgment_total_scores INTEGER NOT NULL,
  question_total_count INTEGER NOT NULL,
  question_total_scores INTEGER NOT NULL,
  create_time DATE NOT NULL,
  "DELETE" INTEGER NOT NULL,
  did_count INTEGER NOT NULL,
  create_user_id INTEGER NOT NULL,
  subject_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_paper START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_paper
	BEFORE INSERT OR UPDATE OF id ON exam_paper
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_paper.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_paper_detail (
  id INTEGER NOT NULL PRIMARY KEY,
  "ORDER" INTEGER NOT NULL,
  "DELETE" INTEGER NOT NULL,
  main_id INTEGER NOT NULL,
  question_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_paper_detail START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_paper_detail
	BEFORE INSERT OR UPDATE OF id ON exam_paper_detail
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_paper_detail.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_question (
  id INTEGER NOT NULL PRIMARY KEY,
  "TYPE" INTEGER NOT NULL,
  difficulty INTEGER NOT NULL,
  scores INTEGER NOT NULL,
  title CLOB NOT NULL,
  judgment INTEGER NOT NULL,
  analysis CLOB,
  create_time DATE NOT NULL,
  "DELETE" INTEGER NOT NULL,
  chapter_id INTEGER NOT NULL,
  create_user_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_question START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_question
	BEFORE INSERT OR UPDATE OF id ON exam_question
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_question.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_question_feedback (
  id INTEGER NOT NULL PRIMARY KEY,
  "TYPE" INTEGER NOT NULL,
  "DESC" CLOB,
  create_time DATE NOT NULL,
  status INTEGER NOT NULL,
  process_time DATE DEFAULT NULL,
  create_user_id INTEGER NOT NULL,
  main_id INTEGER NOT NULL,
  process_user_id INTEGER DEFAULT NULL
);
CREATE SEQUENCE seq_exam_question_feedback START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_question_feedback
	BEFORE INSERT OR UPDATE OF id ON exam_question_feedback
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_question_feedback.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_question_fill (
  id INTEGER NOT NULL PRIMARY KEY,
  content CLOB NOT NULL,
  "ORDER" INTEGER NOT NULL,
  "DELETE" INTEGER NOT NULL,
  main_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_question_fill START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_question_fill
	BEFORE INSERT OR UPDATE OF id ON exam_question_fill
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_question_fill.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE exam_question_option (
  id INTEGER NOT NULL PRIMARY KEY,
  content CLOB NOT NULL,
  "RIGHT" INTEGER NOT NULL,
  "DELETE" INTEGER NOT NULL,
  main_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_exam_question_option START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_exam_question_option
	BEFORE INSERT OR UPDATE OF id ON exam_question_option
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_exam_question_option.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE knowledge_base (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(200) NOT NULL,
  feature CLOB NOT NULL,
  "DESC" CLOB,
  create_time DATE NOT NULL,
  "DELETE" INTEGER NOT NULL,
  chapter_id INTEGER NOT NULL,
  create_user_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_knowledge_base START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_knowledge_base
	BEFORE INSERT OR UPDATE OF id ON knowledge_base
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_knowledge_base.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE knowledge_base_feedback (
  id INTEGER NOT NULL PRIMARY KEY,
  "TYPE" INTEGER NOT NULL,
  "DESC" CLOB,
  create_time DATE NOT NULL,
  status INTEGER NOT NULL,
  process_time DATE DEFAULT NULL,
  create_user_id INTEGER NOT NULL,
  main_id INTEGER NOT NULL,
  process_user_id INTEGER DEFAULT NULL
);
CREATE SEQUENCE seq_knowledge_base_feedback START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_knowledge_base_feedback
	BEFORE INSERT OR UPDATE OF id ON knowledge_base_feedback
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_knowledge_base_feedback.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;


CREATE TABLE practise_answer_fill_log (
  id INTEGER NOT NULL PRIMARY KEY,
  content CLOB NOT NULL,
  "ORDER" INTEGER NOT NULL,
  main_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_practise_answer_fill_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_practise_answer_fill_log
	BEFORE INSERT OR UPDATE OF id ON practise_answer_fill_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_practise_answer_fill_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE practise_answer_log (
  id INTEGER NOT NULL PRIMARY KEY,
  status INTEGER DEFAULT NULL,
  main_id INTEGER NOT NULL,
  question_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_practise_answer_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_practise_answer_log
	BEFORE INSERT OR UPDATE OF id ON practise_answer_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_practise_answer_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE practise_answer_option_log (
  id INTEGER NOT NULL PRIMARY KEY,
  main_id INTEGER NOT NULL,
  option_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_practise_answer_option_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_practise_answer_option_log
	BEFORE INSERT OR UPDATE OF id ON practise_answer_option_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_practise_answer_option_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE practise_error_book (
  id INTEGER NOT NULL PRIMARY KEY,
  last_time DATE NOT NULL,
  wrong_count INTEGER NOT NULL,
  create_user_id INTEGER NOT NULL,
  last_answer_log_id INTEGER NOT NULL,
  question_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_practise_error_book START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_practise_error_book
	BEFORE INSERT OR UPDATE OF id ON practise_error_book
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_practise_error_book.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE practise_log (
  id INTEGER NOT NULL PRIMARY KEY,
  "TYPE" INTEGER NOT NULL,
  create_time DATE NOT NULL,
  submit_time DATE DEFAULT NULL,
  right_count INTEGER NOT NULL,
  wrong_count INTEGER NOT NULL,
  total_count INTEGER NOT NULL,
  begin_answer_id INTEGER DEFAULT NULL,
  chapter_id INTEGER DEFAULT NULL,
  create_user_id INTEGER NOT NULL,
  end_answer_id INTEGER DEFAULT NULL,
  subject_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_practise_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_practise_log
	BEFORE INSERT OR UPDATE OF id ON practise_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_practise_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE staff_department (
  id INTEGER NOT NULL PRIMARY KEY,
  name VARCHAR2(100) NOT NULL,
  notes VARCHAR2(500) DEFAULT NULL,
  parent_id INTEGER DEFAULT NULL,
  lft INTEGER NOT NULL,
  rgt INTEGER NOT NULL
);
CREATE SEQUENCE seq_staff_department START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_staff_department
	BEFORE INSERT OR UPDATE OF id ON staff_department
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_staff_department.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE staff_user (
  id INTEGER NOT NULL PRIMARY KEY,
  password VARCHAR2(128) NOT NULL,
  last_login DATE DEFAULT NULL,
  is_superuser INTEGER NOT NULL,
  "TYPE" INTEGER NOT NULL,
  username VARCHAR2(30) NOT NULL,
  name VARCHAR2(30) NOT NULL,
  is_active INTEGER NOT NULL,
  date_joined DATE NOT NULL,
  department_id INTEGER DEFAULT NULL
);
CREATE SEQUENCE seq_staff_user START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_staff_user
	BEFORE INSERT OR UPDATE OF id ON staff_user
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_staff_user.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE staff_user_groups (
  id INTEGER NOT NULL PRIMARY KEY,
  user_id INTEGER NOT NULL,
  group_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_staff_user_groups START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_staff_user_groups
	BEFORE INSERT OR UPDATE OF id ON staff_user_groups
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_staff_user_groups.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE staff_user_user_permissions (
  id INTEGER NOT NULL PRIMARY KEY,
  user_id INTEGER NOT NULL,
  permission_id INTEGER NOT NULL
);
CREATE SEQUENCE seq_staff_user_pers START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_staff_user_pers
	BEFORE INSERT OR UPDATE OF id ON staff_user_user_permissions
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_staff_user_pers.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;

CREATE TABLE sys_log (
  id INTEGER NOT NULL PRIMARY KEY,
  "TYPE" INTEGER NOT NULL,
  description VARCHAR2(1000) NOT NULL,
  data CLOB,
  create_time DATE NOT NULL,
  user_id INTEGER DEFAULT NULL
);
CREATE SEQUENCE seq_sys_log START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER tr_sys_log
	BEFORE INSERT OR UPDATE OF id ON sys_log
	FOR EACH ROW
	BEGIN
		IF ( :NEW.id = 0 OR :NEW.id IS NULL ) THEN
			SELECT seq_sys_log.NEXTVAL INTO :NEW.id FROM DUAL;
		END IF;
	END;