-- 创建消息表
drop table if exists lucene$message;
create table lucene$message(
    me_id bigint not null primary key auto_increment,
    me_table_name varchar(64) not null,
    me_method_type varchar(6) not null,
    me_data_id int not null,
    me_data text,
    me_priority int default 0,
    me_retry_count int default 0,
    me_create_time datetime not null
);

-- 创建消息历史表
drop table if exists lucene$message_history;
create table lucene$message_history(
    mh_id bigint not null primary key auto_increment,
    mh_dequeue_time datetime not null,
    me_id bigint not null,
    me_table_name varchar(64) not null,
    me_method_type varchar(6) not null,
    me_data_id int not null,
    me_data text,
    me_priority int default 0,
    me_create_time datetime not null
);

-- 创建存储过程 入队消息
drop procedure if exists enqueue_lucene_message;
delimiter $$
create procedure enqueue_lucene_message(in v_table_name varchar(64), v_method_type varchar(6), v_data_id int, v_data text, v_priority int)
begin
	insert into lucene$message (me_table_name, me_method_type, me_data_id, me_data, me_priority, me_create_time) values(v_table_name, v_method_type, v_data_id, v_data, v_priority, sysdate());
end;$$
delimiter ;

-- 创建存储过程 出队消息
drop procedure if exists dequeue_lucene_message;
delimiter $$
create procedure dequeue_lucene_message(in v_id bigint)
begin
	insert into lucene$message_history (mh_dequeue_time, me_id, me_table_name, me_method_type, me_data_id, me_data, me_priority, me_create_time) select sysdate(), me_id, me_table_name, me_method_type, me_data_id, me_data, me_priority, me_create_time from lucene$message where me_id = v_id;
	delete from lucene$message where me_id = v_id;
end;$$
delimiter ;

-- ----------------------------
-- Triggers structure for table product$brand
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_brand_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_brand_i` AFTER INSERT ON `product$brand` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$brand';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.br_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$brand
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_brand_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_brand_u` AFTER UPDATE ON `product$brand` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$brand';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.br_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$brand
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_brand_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_brand_d` AFTER DELETE ON `product$brand` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$brand';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.br_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$component
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_component_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_component_i` AFTER INSERT ON `product$component` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=new.cmp_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='v$product$cmpgoods';
    set v_data='cmpId';
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$component
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_component_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_component_u` AFTER UPDATE ON `product$component` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.cmp_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='v$product$cmpgoods';
    set v_data='cmpId';
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$component
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_component_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_component_d` AFTER DELETE ON `product$component` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.cmp_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);

    set v_table_name='v$product$cmpgoods';
    set v_data='cmpId';
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$kind
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_kind_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_kind_i` AFTER INSERT ON `product$kind` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$kind';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.ki_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$kind
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_kind_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_kind_u` AFTER UPDATE ON `product$kind` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$kind';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.ki_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$kind
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_kind_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_kind_d` AFTER DELETE ON `product$kind` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$kind';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.ki_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$propertyvalue
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_propertyvalue_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_propertyvalue_i` AFTER INSERT ON `product$propertyvalue` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=new.pv_componentid;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$propertyvalue
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_propertyvalue_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_propertyvalue_u` AFTER UPDATE ON `product$propertyvalue` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.pv_componentid;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table product$propertyvalue
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_propertyvalue_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_propertyvalue_d` AFTER DELETE ON `product$propertyvalue` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'product$component';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 0;

    set v_data_id=old.pv_componentid;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$goods
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_trade_goods_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_i` AFTER INSERT ON `trade$goods` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$cmpgoods';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default 'goId';
    declare v_priority int default 0;

    if new.cmp_uuid then
      set v_data='cmpId';
      select cmp_id into v_data_id from product$component where cmp_uuid=new.cmp_uuid;
    else
      set v_data_id=new.go_id;
    end if;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$goods
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_trade_goods_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_u` AFTER UPDATE ON `trade$goods` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$cmpgoods';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default 'goId';
    declare v_priority int default 0;

    if old.cmp_uuid then
      set v_data='cmpId';
      select cmp_id into v_data_id from product$component where cmp_uuid=old.cmp_uuid;
    else
      set v_data_id=old.go_id;
    end if;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$goods
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_trade_goods_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_trade_goods_d` AFTER DELETE ON `trade$goods` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'v$product$cmpgoods';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default 'goId';
    declare v_priority int default 0;

    if old.cmp_uuid then
      set v_data='cmpId';
      select cmp_id into v_data_id from product$component where cmp_uuid=old.cmp_uuid;
    else
      set v_data_id=old.go_id;
    end if;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_i` AFTER INSERT ON `trade$invoice_fmor` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_u` AFTER UPDATE ON `trade$invoice_fmor` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_d` AFTER DELETE ON `trade$invoice_fmor` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_dt_i` AFTER INSERT ON `trade$invoice_fmor_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_dt_u` AFTER UPDATE ON `trade$invoice_fmor_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmor_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_inv_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_inv_dt_d` AFTER DELETE ON `trade$invoice_fmor_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmor';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_i` AFTER INSERT ON `trade$invoice_fmpu` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_u` AFTER UPDATE ON `trade$invoice_fmpu` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_d` AFTER DELETE ON `trade$invoice_fmpu` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_dt_i` AFTER INSERT ON `trade$invoice_fmpu_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_dt_u` AFTER UPDATE ON `trade$invoice_fmpu_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$invoice_fmpu_dt
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_inv_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_inv_dt_d` AFTER DELETE ON `trade$invoice_fmpu_dt` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$invoice_fmpu';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.invoice_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_i` AFTER INSERT ON `trade$order` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_u` AFTER UPDATE ON `trade$order` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_d` AFTER DELETE ON `trade$order` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_dt_i` AFTER INSERT ON `trade$order_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.order_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_dt_u` AFTER UPDATE ON `trade$order_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.order_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$order_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_order_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_order_dt_d` AFTER DELETE ON `trade$order_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$order';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.order_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_i` AFTER INSERT ON `trade$purchase` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'insert';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_u` AFTER UPDATE ON `trade$purchase` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_d` AFTER DELETE ON `trade$purchase` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'delete';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_dt_i`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_dt_i` AFTER INSERT ON `trade$purchase_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=new.purchase_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_dt_u`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_dt_u` AFTER UPDATE ON `trade$purchase_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.purchase_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;

-- ----------------------------
-- Triggers structure for table trade$purchase_detail
-- ----------------------------
DROP TRIGGER IF EXISTS `lucene_purchase_dt_d`;
delimiter ;;
CREATE DEFINER = `root`@`%` TRIGGER `lucene_purchase_dt_d` AFTER DELETE ON `trade$purchase_detail` FOR EACH ROW begin
	declare v_table_name varchar(64) default 'trade$purchase';
    declare v_method_type varchar(6) default 'update';
    declare v_data_id int;
    declare v_data text default null;
    declare v_priority int default 1;

    set v_data_id=old.purchase_id;
    call enqueue_lucene_message(v_table_name, v_method_type, v_data_id, v_data, v_priority);
end
;;
delimiter ;
