##----system_constant_dat create

DROP TABLE IF EXISTS system_constant_dat;
CREATE TABLE IF NOT EXISTS system_constant_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	name varchar(64) NOT NULL,
	title varchar(128) NOT NULL,
	constant_value text NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX system_constant_dat_name_idx ON system_constant_dat(name);


##----government_mst create

DROP TABLE IF EXISTS government_mst;
CREATE TABLE IF NOT EXISTS government_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	province varchar(64) NOT NULL,
	city varchar(64),
	district varchar(64),
	title text NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX government_mst_province_idx ON government_mst(province);
Create INDEX government_mst_city_idx ON government_mst(city);
Create INDEX government_mst_district_idx ON government_mst(district);


##----government_qr_dat create

DROP TABLE IF EXISTS government_qr_dat;
CREATE TABLE IF NOT EXISTS government_qr_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	government_id int8 NOT NULL,
	province varchar(64) NOT NULL,
	city varchar(64),
	district varchar(64),
	max_count int8 NOT NULL DEFAULT '0',
	limit_date timestamp NOT NULL,
	title text NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX government_qr_dat_province_idx ON government_qr_dat(province);
Create INDEX government_qr_dat_city_idx ON government_qr_dat(city);
Create INDEX government_qr_dat_district_idx ON government_qr_dat(district);


##----account_mst create

DROP TABLE IF EXISTS account_mst;
CREATE TABLE IF NOT EXISTS account_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	login text NOT NULL,
	password text NOT NULL,
	name varchar(64) NOT NULL,
	contact text,
	role varchar(128) NOT NULL,
	user_id int8 NOT NULL DEFAULT '0',
	school_id int8 NOT NULL DEFAULT '0',
	government_id int8 NOT NULL DEFAULT '0',
	modules text NOT NULL,
	comment text,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX account_mst_login_idx ON account_mst(login(255));
Create INDEX account_mst_password_idx ON account_mst(password(255));
Create INDEX account_mst_name_idx ON account_mst(name);


##----school_mst create

DROP TABLE IF EXISTS school_mst;
CREATE TABLE IF NOT EXISTS school_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	school_no text NOT NULL,
	original_source int8 NOT NULL DEFAULT '0',
	title text NOT NULL,
	school_type varchar(64) NOT NULL,
	front_image text NOT NULL,
	comment text NOT NULL,
	address text NOT NULL,
	province varchar(64),
	city varchar(64),
	district varchar(64),
	street text,
	longitude text,
	latitude text,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX school_mst_id_idx ON school_mst(id);
Create INDEX school_mst_school_type_idx ON school_mst(school_type);
Create INDEX school_mst_province_idx ON school_mst(province);
Create INDEX school_mst_city_idx ON school_mst(city);


##----grade_mst create

DROP TABLE IF EXISTS grade_mst;
CREATE TABLE IF NOT EXISTS grade_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	school_id int8 NOT NULL,
	school_no text NOT NULL,
	original_source int8 NOT NULL DEFAULT '0',
	title text NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX grade_mst_school_id_idx ON grade_mst(school_id);


##----class_mst create

DROP TABLE IF EXISTS class_mst;
CREATE TABLE IF NOT EXISTS class_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	school_id int8 NOT NULL,
	school_no text NOT NULL,
	class_no text NOT NULL,
	original_source int8 NOT NULL DEFAULT '0',
	grade_id int8 NOT NULL,
	title text NOT NULL,
	member_count int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX class_mst_school_id_idx ON class_mst(school_id);
Create INDEX class_mst_grade_id_idx ON class_mst(grade_id);
Create INDEX class_mst_class_no_idx ON class_mst(class_no(255));


##----circle_dat create

DROP TABLE IF EXISTS circle_dat;
CREATE TABLE IF NOT EXISTS circle_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	title text NOT NULL,
	member_count int8 NOT NULL DEFAULT '0',
	need_check tinyint(1) NOT NULL DEFAULT '0',
	comment text NOT NULL,
	longitude text NOT NULL,
	latitude text NOT NULL DEFAULT 'UNKNOW',
	address text NOT NULL,
	owner_id int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;



##----circle_member_dat create

DROP TABLE IF EXISTS circle_member_dat;
CREATE TABLE IF NOT EXISTS circle_member_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	circle_id int8 NOT NULL DEFAULT '0',
	user_id int8 NOT NULL DEFAULT '0',
	member_count int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;



##----user_mst create

DROP TABLE IF EXISTS user_mst;
CREATE TABLE IF NOT EXISTS user_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	school_no text NOT NULL DEFAULT '0',
	class_no text NOT NULL DEFAULT '0',
	original_source int8 NOT NULL DEFAULT '0',
	openid varchar(64) NOT NULL DEFAULT 'UNKNOW',
	unionid varchar(64) NOT NULL DEFAULT 'UNKNOW',
	name varchar(64),
	mobile varchar(32),
	account_id int8 NOT NULL DEFAULT '0',
	child_age int8 NOT NULL DEFAULT '1',
	role varchar(128) NOT NULL DEFAULT '0',
	longitude text NOT NULL,
	latitude text NOT NULL DEFAULT 'UNKNOW',
	organization_submit_date timestamp,
	organization_no varchar(255),
	organization_title text,
	legal_person varchar(255),
	organization_contact text,
	legal_person_imgage1 text,
	legal_person_imgage2 text,
	licensen_imgage text,
	other_imgage text,
	organization_status varchar(64) NOT NULL DEFAULT 'NEW',
	ability_point int8 NOT NULL DEFAULT '0',
	service_point int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;



##----social_event_dat create

DROP TABLE IF EXISTS social_event_dat;
CREATE TABLE IF NOT EXISTS social_event_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	school_no text NOT NULL,
	class_no text NOT NULL,
	event_id int8 NOT NULL,
	original_source int8 NOT NULL DEFAULT '0',
	title text NOT NULL,
	author text NOT NULL,
	publish_time timestamp NOT NULL,
	content text NOT NULL,
	scope int8 NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX social_event_dat_school_no_idx ON social_event_dat(school_no(255));
Create INDEX social_event_dat_class_no_idx ON social_event_dat(class_no(255));
Create INDEX social_event_dat_original_source_idx ON social_event_dat(original_source);


##----social_event_member_dat create

DROP TABLE IF EXISTS social_event_member_dat;
CREATE TABLE IF NOT EXISTS social_event_member_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	social_event_id int8 NOT NULL,
	user_id text NOT NULL,
	comment text NOT NULL,
	images text NOT NULL,
	status varchar(64) NOT NULL DEFAULT '0',
	point int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX social_event_member_dat_user_id_idx ON social_event_member_dat(user_id(255));


##----family_event_dat create

DROP TABLE IF EXISTS family_event_dat;
CREATE TABLE IF NOT EXISTS family_event_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	school_no text NOT NULL,
	class_no text NOT NULL,
	event_id int8 NOT NULL,
	original_source int8 NOT NULL DEFAULT '0',
	title text NOT NULL,
	author text NOT NULL,
	publish_time timestamp NOT NULL,
	images text,
	content text NOT NULL,
	scope int8 NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX family_event_dat_school_no_idx ON family_event_dat(school_no(255));
Create INDEX family_event_dat_class_no_idx ON family_event_dat(class_no(255));
Create INDEX family_event_dat_original_source_idx ON family_event_dat(original_source);


##----family_event_member_dat create

DROP TABLE IF EXISTS family_event_member_dat;
CREATE TABLE IF NOT EXISTS family_event_member_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	family_event_id int8 NOT NULL,
	user_id text NOT NULL,
	comment text NOT NULL,
	images text NOT NULL,
	status varchar(64) NOT NULL DEFAULT '0',
	point int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX family_event_member_dat_user_id_idx ON family_event_member_dat(user_id(255));


##----volunteer_event_dat create

DROP TABLE IF EXISTS volunteer_event_dat;
CREATE TABLE IF NOT EXISTS volunteer_event_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	title text NOT NULL,
	start_time timestamp NOT NULL,
	finish_time timestamp NOT NULL,
	position text NOT NULL,
	position_longitude text NOT NULL,
	position_latitude text NOT NULL,
	scope int8 NOT NULL,
	max_member int8 NOT NULL DEFAULT '0',
	time_length varchar(64) NOT NULL,
	leader_name varchar(64) NOT NULL,
	leader_contact varchar(128) NOT NULL,
	venue text NOT NULL,
	status varchar(64) NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;



##----volunteer_event_member_dat create

DROP TABLE IF EXISTS volunteer_event_member_dat;
CREATE TABLE IF NOT EXISTS volunteer_event_member_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	volunteer_event_id int8 NOT NULL,
	user_id text NOT NULL,
	comment text NOT NULL,
	images text NOT NULL,
	position text NOT NULL,
	position_longitude text NOT NULL,
	position_latitude text NOT NULL,
	status varchar(64) NOT NULL DEFAULT 'NEW',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX volunteer_event_member_dat_user_id_idx ON volunteer_event_member_dat(user_id(255));


##----user_certificate_dat create

DROP TABLE IF EXISTS user_certificate_dat;
CREATE TABLE IF NOT EXISTS user_certificate_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	user_id text NOT NULL,
	certificate_id text NOT NULL,
	name varchar(64) NOT NULL,
	mobile varchar(32) NOT NULL,
	address varchar(128) NOT NULL,
	status varchar(64) NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX user_certificate_dat_user_id_idx ON user_certificate_dat(user_id(255));
Create INDEX user_certificate_dat_certificate_id_idx ON user_certificate_dat(certificate_id(255));


##----certificate_mst create

DROP TABLE IF EXISTS certificate_mst;
CREATE TABLE IF NOT EXISTS certificate_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	title varchar(128) NOT NULL,
	front_image text NOT NULL,
	point text,
	status varchar(64) NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;



##----user_point_log create

DROP TABLE IF EXISTS user_point_log;
CREATE TABLE IF NOT EXISTS user_point_log(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	user_id int8 NOT NULL PRIMARY KEY auto_increment,
	action_type int4 NOT NULL,
	point int4 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX user_point_log_user_id_idx ON user_point_log(user_id);


##----course_media_dat create

DROP TABLE IF EXISTS course_media_dat;
CREATE TABLE IF NOT EXISTS course_media_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	course_id int8 NOT NULL DEFAULT '0',
	title varchar(128) NOT NULL,
	tags text NOT NULL,
	front_image text NOT NULL,
	media text NOT NULL,
	teacher varchar(128),
	is_free tinyint(1) NOT NULL DEFAULT '0',
	price float(5,2) NOT NULL DEFAULT '0',
	view_count int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX course_media_dat_course_id_idx ON course_media_dat(course_id);


##----media_tag_dat create

DROP TABLE IF EXISTS media_tag_dat;
CREATE TABLE IF NOT EXISTS media_tag_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	tag varchar(128) NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX media_tag_dat_tag_idx ON media_tag_dat(tag);


##----course_mst create

DROP TABLE IF EXISTS course_mst;
CREATE TABLE IF NOT EXISTS course_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	parent_category_id int8 NOT NULL,
	sub_category_id int8 NOT NULL,
	title varchar(128) NOT NULL,
	front_image text NOT NULL,
	teacher_profile text,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX course_mst_id_idx ON course_mst(id);
Create INDEX course_mst_title_idx ON course_mst(title);

##----user_point_log create

DROP TABLE IF EXISTS user_point_log;
CREATE TABLE IF NOT EXISTS user_point_log(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	user_id int8 NOT NULL,
	media_id int8 NOT NULL,
	is_free tinyint(1) NOT NULL DEFAULT '0',
	money float(5,2) NOT NULL DEFAULT '0',
	order_no varchar(255),
	mchid_order_no varchar(255),
	status varchar(64),
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8mb4;

Create INDEX user_point_log_user_id_idx ON user_point_log(user_id);