
# This script shows how to install the synchronization system 
# using the SyncManager object

use SynKit;

### CHANGE THESE TO MATCH YOUR SYSTEM  ##########################
my $dbi_connect_string = 'dbi:Pg:dbname=test;host=snoopy';	#
my $db_user = 'test';						#
my $db_pass = 'test';						#
#################################################################
my $ret; #holds return value


#create an instance of the sync manager object
my $m = SyncManager->new($dbi_connect_string,$db_user,$db_pass);

#Call this to install the syncronization management tables, etc.
$ret = $m->INSTALL;
die "Handle this error: $ret\n\n" if $ret;



#create a test table for us to demonstrate with
use DBI;
my $dbh = DBI->connect($dbi_connect_string,$db_user,$db_pass);
$dbh->do("create table sync_test (name text)");
$dbh->do("insert into sync_test values ('rob')");
$dbh->do("insert into sync_test values ('rob')");
$dbh->do("insert into sync_test values ('rob')");
$dbh->do("insert into sync_test values ('ted')");
$dbh->do("insert into sync_test values ('ted')");
$dbh->do("insert into sync_test values ('ted')");
$dbh->disconnect;




#call this to "publish" a table
$ret = $m->publish('sync_test');
print "Handle this error: $ret\n\n" if $ret;

#call this to "subscribe" a user/node to a publication (table)
$ret = $m->subscribe('JOE','REMOTE_NODE_NAME','sync_test');
print "Handle this error: $ret\n\n" if $ret;

#call this to "subscribe" a user/node to a publication (table)
$ret = $m->subscribe('KEN','ANOTHER_REMOTE_NODE_NAME','sync_test');
print "Handle this error: $ret\n\n" if $ret;


print "Now you can do: 'perl sync.pl' a few times to play\n\n";
print "Do 'perl sync_uninstall.pl' to uninstall the system\n";

