##----system_const_dat create

DROP TABLE IF EXISTS system_const_dat;
CREATE TABLE IF NOT EXISTS system_const_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=utf8;

Create INDEX system_const_dat_name_idx ON system_const_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=utf8;

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


##----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=utf8;

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 varchar(64) NOT NULL,
	comment text NOT NULL,
	address text NOT NULL,
	province varchar(64),
	city varchar(64),
	district varchar(64),
	street text,
	longitude text NOT NULL,
	latitude text NOT NULL DEFAULT 'UNKNOW',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX school_mst_id_idx ON school_mst(id);
Create INDEX school_mst_title_idx ON school_mst(title(255));
Create INDEX school_mst_school_type_idx ON school_mst(school_type);


##----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=utf8;

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

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',
	owner_id int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;



##----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=utf8;



##----teacher_mst create

DROP TABLE IF EXISTS teacher_mst;
CREATE TABLE IF NOT EXISTS teacher_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	school_id int8 NOT NULL,
	grade_id int8 NOT NULL,
	class_id int8 NOT NULL,
	name varchar(64) NOT NULL,
	contact varchar(64),
	qq_no varchar(64) DEFAULT '1',
	area varchar(64),
	sex varchar(64) NOT NULL DEFAULT 'UNKNOW',
	channel_no varchar(64) NOT NULL,
	status varchar(64) NOT NULL DEFAULT '0',
	uid varchar(128),
	account_id int8 NOT NULL DEFAULT '0',
	point int4 NOT NULL DEFAULT '0',
	zfb_account varchar(128),
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX teacher_mst_channel_no_idx ON teacher_mst(channel_no);
Create INDEX teacher_mst_status_idx ON teacher_mst(status);


##----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_id int8 NOT NULL,
	class_id int8 NOT NULL,
	name varchar(64) NOT NULL,
	tel_no varchar(32) NOT NULL,
	unionid varchar(64) NOT NULL DEFAULT 'UNKNOW',
	status varchar(64) NOT NULL DEFAULT '0',
	account_id int8 NOT NULL DEFAULT '0',
	role varchar(128) NOT NULL DEFAULT '0',
	point int8 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 varchar(255),
	legal_person_imgage2 varchar(255),
	licensen_imgage varchar(255),
	other_imgage varchar(255),
	organization_status varchar(64) NOT NULL DEFAULT 'NEW',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX user_mst_status_idx ON user_mst(status);


##----event_dat create

DROP TABLE IF EXISTS event_dat;
CREATE TABLE IF NOT EXISTS 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 DEFAULT 'NEW',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;



##----organization_mst create

DROP TABLE IF EXISTS organization_mst;
CREATE TABLE IF NOT EXISTS organization_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	organization_submit_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	organization_no varchar(255) NOT NULL,
	organization_title text NOT NULL,
	legal_person varchar(255) NOT NULL,
	organization_contact text,
	legal_person_imgage1 varchar(255),
	legal_person_imgage2 varchar(255),
	licensen_imgage varchar(255),
	other_imgage varchar(255),
	organization_status varchar(64) NOT NULL DEFAULT 'NEW',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;



##----user_comment_dat create

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

Create INDEX user_comment_dat_user_id_idx ON user_comment_dat(user_id);
Create INDEX user_comment_dat_account_id_idx ON user_comment_dat(account_id);


##----user_favorite_dat create

DROP TABLE IF EXISTS user_favorite_dat;
CREATE TABLE IF NOT EXISTS user_favorite_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	user_id int8 NOT NULL,
	data_type varchar(64) NOT NULL,
	data_id int8 NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX user_favorite_dat_user_id_idx ON user_favorite_dat(user_id);
Create INDEX user_favorite_dat_data_id_idx ON user_favorite_dat(data_id);
Create INDEX user_favorite_dat_data_type_idx ON user_favorite_dat(data_type);


##----user_sign_dat create

DROP TABLE IF EXISTS user_sign_dat;
CREATE TABLE IF NOT EXISTS user_sign_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	object_date varchar(10) NOT NULL,
	user_id int8 NOT NULL,
	article_id int8 NOT NULL DEFAULT '0',
	point int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX user_sign_dat_object_date_idx ON user_sign_dat(object_date);
Create INDEX user_sign_dat_user_id_idx ON user_sign_dat(user_id);


##----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',
	point_left int4 NOT NULL DEFAULT '0',
	status varchar(255) NOT NULL DEFAULT 'WAITING',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX user_point_log_user_id_idx ON user_point_log(user_id);


##----user_staff_relation_dat create

DROP TABLE IF EXISTS user_staff_relation_dat;
CREATE TABLE IF NOT EXISTS user_staff_relation_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	user_id int8 NOT NULL,
	account_id int8 NOT NULL,
	comment text NOT NULL,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX user_staff_relation_dat_user_id_idx ON user_staff_relation_dat(user_id);
Create INDEX user_staff_relation_dat_account_id_idx ON user_staff_relation_dat(account_id);


##----article_dat create

DROP TABLE IF EXISTS article_dat;
CREATE TABLE IF NOT EXISTS article_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	category_id int8 NOT NULL,
	title varchar(128) NOT NULL,
	front_image text,
	mp3 varchar(64),
	video_url text,
	comment text NOT NULL,
	display_order int4 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX article_dat_display_order_idx ON article_dat(display_order);
Create INDEX article_dat_title_idx ON article_dat(title);


##----article_tags_dat create

DROP TABLE IF EXISTS article_tags_dat;
CREATE TABLE IF NOT EXISTS article_tags_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	tag text,
	click_count int8,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX article_tags_dat_tag_idx ON article_tags_dat(tag(255));


##----article_category_mst create

DROP TABLE IF EXISTS article_category_mst;
CREATE TABLE IF NOT EXISTS article_category_mst(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	title text NOT NULL,
	thumbnail text,
	display_order int8 NOT NULL DEFAULT '0',
	is_valid tinyint(1) NOT NULL DEFAULT '1',
	user_status text,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX article_category_mst_thumbnail_idx ON article_category_mst(thumbnail(255));
Create INDEX article_category_mst_is_valid_idx ON article_category_mst(is_valid);


##----article_comment_dat create

DROP TABLE IF EXISTS article_comment_dat;
CREATE TABLE IF NOT EXISTS article_comment_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	article_id int8 NOT NULL DEFAULT '0',
	icon text NOT NULL,
	nickname text NOT NULL,
	comment text,
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX article_comment_dat_article_id_idx ON article_comment_dat(article_id);


##----miniplay_traffic_click_log create

DROP TABLE IF EXISTS miniplay_traffic_click_log;
CREATE TABLE IF NOT EXISTS miniplay_traffic_click_log(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	channel_id varchar(64),
	openid varchar(255) NOT NULL,
	adid int8 NOT NULL,
	is_ok tinyint(1) NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX miniplay_traffic_click_log_channel_id_idx ON miniplay_traffic_click_log(channel_id);
Create INDEX miniplay_traffic_click_log_id_idx ON miniplay_traffic_click_log(id);
Create INDEX miniplay_traffic_click_log_registration_date_idx ON miniplay_traffic_click_log(registration_date);


##----miniplay_traffic_click_dat create

DROP TABLE IF EXISTS miniplay_traffic_click_dat;
CREATE TABLE IF NOT EXISTS miniplay_traffic_click_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	object_date varchar(10) NOT NULL,
	channel_id varchar(64) NOT NULL,
	click_count int8 NOT NULL DEFAULT '0',
	click_count_real int8 NOT NULL DEFAULT '0',
	unique_click_count int8 NOT NULL DEFAULT '0',
	unique_click_count_real int8 NOT NULL DEFAULT '0',
	history_unique_click_count int8 NOT NULL DEFAULT '0',
	history_unique_click_count_real int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX miniplay_traffic_click_dat_object_date_idx ON miniplay_traffic_click_dat(object_date);


##----user_access_dat create

DROP TABLE IF EXISTS user_access_dat;
CREATE TABLE IF NOT EXISTS user_access_dat(
	id bigint unsigned NOT NULL PRIMARY KEY auto_increment,
	registration_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	object_date varchar(10) NOT NULL,
	register_count int8 NOT NULL,
	login_count int8 NOT NULL DEFAULT '0',
	delete_flg tinyint(1) NOT NULL DEFAULT '0'
) ENGINE = INNODB DEFAULT CHARSET=utf8;

Create INDEX user_access_dat_object_date_idx ON user_access_dat(object_date);


