# -----------------------------------------------------------------
# WebLib change logging tables
#
# The tables must be present in all WebLib applications 

# Last modified: 		9 May 2007
# -----------------------------------------------------------------

drop table if exists weblib_change_log;
drop table if exists weblib_change_log_subjects;

# -----------------------------------------------------------------
CREATE TABLE IF NOT EXISTS weblib_change_log (
	log_id				bigint				not null auto_increment,
	log_datetime		int unsigned		not null,
	user_id				int unsigned		null,
	changetype			char(1)				not null,
	logged_table_num	tinyint unsigned	not null,
	logged_row_id		int unsigned		not null,
	snapshot			longtext			not null,
	remarks				text				not null,
	unit_type			tinyint unsigned	null,
	unit_id				int unsigned		null,
	
	primary key 							(log_id),
	index				i_datetime			(log_datetime),
	index				i_user_id			(user_id),
	index				i_logged			(logged_row_id, logged_table_num),
	index				i_unit				(unit_id, unit_type)
) type=myisam character set utf8 collate utf8_general_ci;
# -----------------------------------------------------------------
CREATE TABLE IF NOT EXISTS weblib_change_log_subjects (
	log_id				bigint				not null,
	subject_table_num	tinyint unsigned	not null,
	subject_row_id		int unsigned		not null,
	
	index				i_log_id			(log_id),
	index				i_subject			(subject_row_id, subject_table_num)
	
) type=myisam character set utf8 collate utf8_general_ci;
# -----------------------------------------------------------------