--
-- Licensed to JumpMind Inc under one or more contributor
-- license agreements.  See the NOTICE file distributed
-- with this work for additional information regarding
-- copyright ownership.  JumpMind Inc licenses this file
-- to you under the GNU General Public License, version 3.0 (GPLv3)
-- (the "License"); you may not use this file except in compliance
-- with the License.
--
-- You should have received a copy of the GNU General Public License,
-- version 3.0 (GPLv3) along with this library; if not, see
-- <http://www.gnu.org/licenses/>.
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied.  See the License for the
-- specific language governing permissions and limitations
-- under the License.
--

------------------------------------------------------------------------------
-- Sample Data
------------------------------------------------------------------------------
-- insert into item (item_id, name) values (11000001, 'Yummy Gum');
-- insert into item_selling_price (item_id, store_id, price, cost) values (11000001, '001',0.20, 0.10);
-- insert into item_selling_price (item_id, store_id, price, cost) values (11000001, '002',0.30, 0.20);

-- insert into sale_transaction (tran_id, store_id, workstation, day, seq) 
-- values (900, '001', '3', '2012-12-01', 90);
-- insert into sale_return_line_item (tran_id, item_id, price, quantity, returned_quantity)
-- values (900, 11000001, 0.20, 1, 0);

------------------------------------------------------------------------------
-- Sample Symmetric Configuration
------------------------------------------------------------------------------

delete from sym_trigger_router;
delete from sym_trigger;
delete from sym_router;
delete from sym_channel where channel_id in ('orders', 'order_items');
delete from sym_node_group_link;
delete from sym_node_group;
delete from sym_node_host;
delete from sym_node_identity;
delete from sym_node_security;
delete from sym_node;


# Create Channels for logically grouped tables
insert into sym_channel 
(channel_id, processing_order, max_batch_size, enabled, description)
values('dining', 1, 100000, 1, 'sale_transactional data from register and back office');

insert into sym_channel 
(channel_id, processing_order, max_batch_size, enabled, description)
values('menu', 1, 100000, 1, 'Item and pricing data');

insert into sym_channel 
(channel_id, processing_order, max_batch_size, enabled, description)
values('order', 1, 100000, 1, 'Item and pricing data');

# Create Node Groups and Links
insert into sym_node_group (node_group_id) values ('sx');
insert into sym_node_group (node_group_id) values ('store');

insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('sx', 'store', 'W');
insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('store', 'sx', 'P');

# Create Trigger for Tables
insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('zones','zones','dining',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('menus','menus','menu',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('menu_categories','menu_categories','menu',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('accounts','accounts','menu',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('menu_items','menu_items','menu',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('menu_item_attributes','menu_item_attributes','menu',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('menu_item_options','menu_item_options','menu',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('menu_item_instances','menu_item_instances','menu',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('orders','orders','order',current_timestamp,current_timestamp);

insert into sym_trigger 
(trigger_id,source_table_name,channel_id,last_update_time,create_time)
values('order_items','order_items','order',current_timestamp,current_timestamp);


# Create Routers for Nodes
insert into sym_router 
(router_id,source_node_group_id,target_node_group_id,router_type,create_time,last_update_time)
values('sx_2_store', 'sx', 'store', 'default',current_timestamp, current_timestamp);

insert into sym_router 
(router_id,source_node_group_id,target_node_group_id,router_type,create_time,last_update_time)
values('store_2_sx', 'store', 'sx', 'default',current_timestamp, current_timestamp);

-- insert into sym_router 
-- (router_id,source_node_group_id,target_node_group_id,router_type,router_expression,create_time,last_update_time)
-- values('sx_2_one_store', 'sx', 'store', 'column','STORE_ID=:EXTERNAL_ID or OLD_STORE_ID=:EXTERNAL_ID',current_timestamp, current_timestamp);


# Add triggers for tables with router
insert into sym_trigger_router 
(trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('accounts','sx_2_store', 100, current_timestamp, current_timestamp);

-- insert into sym_trigger_router 
-- (trigger_id,router_id,initial_load_order,initial_load_select,last_update_time,create_time)
-- values('accounts','sx_2_one_store',100,'store_id=''$(externalId)''',current_timestamp,current_timestamp);

insert into sym_trigger_router 
(trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('orders','store_2_sx', 200, current_timestamp, current_timestamp);

insert into sym_trigger_router 
(trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('order_items','store_2_sx', 200, current_timestamp, current_timestamp);

insert into sym_node (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,batch_in_error_count,created_at_node_id) 
 values ('000','sx','000',1,null,null,null,null,null,current_timestamp,null,0,0,'000');
insert into sym_node (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,batch_in_error_count,created_at_node_id) 
 values ('001','store','001',1,null,null,null,null,null,current_timestamp,null,0,0,'000');
insert into sym_node (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,batch_in_error_count,created_at_node_id) 
 values ('002','store','002',1,null,null,null,null,null,current_timestamp,null,0,0,'000');


insert into sym_node_security (node_id,node_password,registration_enabled,registration_time,initial_load_enabled,initial_load_time,created_at_node_id) 
 values ('000','acd36ce830d1fda466eec921433f38',0,current_timestamp,0,current_timestamp,'000');
insert into sym_node_security (node_id,node_password,registration_enabled,registration_time,initial_load_enabled,initial_load_time,created_at_node_id) 
 values ('001','acd36ce830d1fda466eec921433f38',1,null,1,null,'000');
insert into sym_node_security (node_id,node_password,registration_enabled,registration_time,initial_load_enabled,initial_load_time,created_at_node_id) 
 values ('002','acd36ce830d1fda466eec921433f38',1,null,1,null,'000');

insert into sym_node_identity values ('000');
