소스 검색

wip

* modifying to use with sqlite db.
clementinecomputing 6 년 전
부모
커밋
7194be3f9f

+ 152 - 37
server/daemons/billing_server/billing_server.pl

@@ -34,8 +34,14 @@ use POSIX;
 use Data::Dumper;
 
 #use OrgDB;
+#push @INC, "/home/bus/popufare/server/scripts";
+use lib qw( . );
+use RideLogic;
 
-my $ORG = "ORG";
+#my $ORG = "ORG";
+my $ORG = "TEST-ORG";
+
+my $isMySQL = 0;
 
 #my $database_path = 'DBI:mysql:busdb';
 my $database_path = 'DBI:SQLite:dbname=../bus.sqlite';
@@ -157,22 +163,26 @@ sub ExpirePass {
   my $query = $dbh->prepare("select p.user_pass_id, p.queue_order, p.rule, p.nrides_remain, p.nday_expiration, rc.ruleclass
                                from user_pass p, rule_class rc
                               where p.logical_card_id = ? and p.active = 1 and p.expired = 0 and
-                                    ( ( rc.ruleclass = 'NDAY' and p.nday_expiration < now() ) or
+                                    ( ( rc.ruleclass = 'NDAY' and p.nday_expiration < " . ($isMySQL ? "now()" : "datetime('now', 'localtime')") . ") or
                                     ( rc.ruleclass = 'NRIDE' and p.nrides_remain <= 0 ) or
                                     ( rc.rulename = 'PREACTIVE' ) ) ");
   $query->execute($cardid);
+  my $href = $query->fetchrow_hashref;
   if ($query->rows == 0) { $dbh->commit; return; }
 
-  my $href = $query->fetchrow_hashref;
+print "#bill: cp0\n";
+
   my $passid = $href->{'user_pass_id'};
   my $current_q_num = $href->{'queue_order'};
 
   # expire old pass
   my $audit_pass_id = audit_user_pass_start($dbh, $passid, "billing_server: ExpirePass: deactivating and expiring pass");
-  $query = $dbh->prepare("update user_pass set active = 0, expired = 1, deactivated = now() where user_pass_id = ?");
+  $query = $dbh->prepare("update user_pass set active = 0, expired = 1, deactivated = " . ($isMySQL ? "now()" : "datetime('now', 'localtime')") . " where user_pass_id = ?");
   $query->execute($passid);
   audit_user_pass_end($dbh, $passid, $audit_pass_id);
 
+print "#bill: cp1\n";
+
   # activate new pass
   $query = $dbh->prepare("select p.user_pass_id, p.rule, p.nday_orig, p.nday_expiration, p.nrides_orig, p.queue_order, rc.ruleclass
                             from user_pass p, rule_class rc
@@ -185,21 +195,31 @@ sub ExpirePass {
                                                     and t.expired = 0) ");
   $query->execute($cardid, $cardid, $current_q_num);
 
+
+print "#bill: cp2\n";
+  $href = $query->fetchrow_hashref;
+
   # no passes left, put in reject rule, finish transaction
   if ($query->rows == 0) {
-    $query = $dbh->prepare("lock tables active_rider_table write");
-    $query->execute();
+    if ($isMySQL) {
+      $query = $dbh->prepare("lock tables active_rider_table write");
+      $query->execute();
+    }
     $query = $dbh->prepare("insert into active_rider_table (logical_card_id, rfid_token, mag_token, rule_name, rule_param, deleted, notes)
                                                     values (?,?,?,?,?,?,?)");
     $query->execute($cardid, @oldrow[1,2], $ORG . '-REJECT', 'reject', 0, $oldrow[7]);
     $dbh->commit;
-    $query = $dbh->prepare("unlock tables");
-    $query->execute();
+    if ($isMySQL) {
+      $query = $dbh->prepare("unlock tables");
+      $query->execute();
+    }
     return;
   }
 
+print "#bill: cp3\n";
+
   # else make new pass active and update art with new pass
-  $href = $query->fetchrow_hashref;
+  #$href = $query->fetchrow_hashref;
 
   my $pass_param = '';
   if      ($href->{'ruleclass'} eq 'NRIDE') { 
@@ -214,14 +234,22 @@ sub ExpirePass {
   $query->execute($ride_time, $href->{'user_pass_id'} );
   audit_user_pass_end($dbh, $href->{'user_pass_id'}, $audit_pass_id);
 
-  $query = $dbh->prepare("lock tables active_rider_table write");
-  $query->execute();
+print "#bill: cp4\n";
+
+  if ($isMySQL) {
+    $query = $dbh->prepare("lock tables active_rider_table write");
+    $query->execute();
+  }
   $query = $dbh->prepare("insert into active_rider_table (logical_card_id, rfid_token, mag_token, rule_name, rule_param, deleted, notes)
                                                   values (?,?,?,?,?,?,?)");
   $query->execute($cardid, @oldrow[1,2], $href->{'rule'}, $pass_param, 0, $oldrow[7]);
   $dbh->commit;
-  $query = $dbh->prepare("unlock tables");
-  $query->execute();
+  if ($isMySQL) {
+    $query = $dbh->prepare("unlock tables");
+    $query->execute();
+  }
+
+print "#bill: cp5\n";
 
 }
 
@@ -239,8 +267,21 @@ sub AdvanceRiderPass {
   $dbh->{RaiseError} = 1;
   $dbh->{PrintError} = 1;
 
+print "#bill: advance: cp0, logical_card_id " . $logical_card_id . "\n";
+
   $dbh->begin_work;
 
+#  my $sth_find = $dbh->prepare('SELECT active_rider_table.logical_card_id, 	active_rider_table.rfid_token, 
+#				       active_rider_table.mag_token, 	        active_rider_table.rule_name, 
+#				       active_rider_table.rule_param, 	        active_rider_table.deleted, 
+#				       active_rider_table.parent_entity, 	active_rider_table.notes,
+#                                       active_rider_table.seq_num
+#				  FROM active_rider_table
+#				 WHERE logical_card_id = ? 
+#				   AND NOT(deleted) 
+#				   AND seq_num = (SELECT max(seq_num) FROM active_rider_table WHERE logical_card_id = ?) ');
+#  my $xx = $sth_find->execute($logical_card_id, $logical_card_id);
+
   my $sth_find = $dbh->prepare('SELECT active_rider_table.logical_card_id, 	active_rider_table.rfid_token, 
 				       active_rider_table.mag_token, 	        active_rider_table.rule_name, 
 				       active_rider_table.rule_param, 	        active_rider_table.deleted, 
@@ -249,9 +290,10 @@ sub AdvanceRiderPass {
 				  FROM active_rider_table
 				 WHERE logical_card_id = ? 
 				   AND NOT(deleted) 
-				   AND seq_num = (SELECT max(seq_num) FROM active_rider_table WHERE logical_card_id = ?) ');
-  $sth_find->execute($logical_card_id, $logical_card_id);
-  if ($sth_find->rows != 1) { $dbh->commit; return; }
+                                   order by seq_num desc limit 1;');
+  $sth_find->execute($logical_card_id);
+
+  #if ($sth_find->rows != 1) { $dbh->commit; return; }
 
   #@oldrow:
   #0. logical_card_id
@@ -265,6 +307,10 @@ sub AdvanceRiderPass {
   #8. seq_num
   my @oldrow = $sth_find->fetchrow_array();
 
+  if (not @oldrow) { $dbh->commit; return; }
+
+print ">> $logical_card_id, $billing_ride_time\n";
+
   my $sth_pass = $dbh->prepare("select p.user_pass_id, p.nrides_remain, p.nday_orig, p.nday_expiration, p.rule
                                   from user_pass p, user_card c
                                  where p.logical_card_id = ? 
@@ -274,44 +320,86 @@ sub AdvanceRiderPass {
                                    and p.expired = 0 
                                    and p.activated <= ?");
   $sth_pass->execute($logical_card_id, $billing_ride_time);
+
+  my $pass = $sth_pass->fetchrow_hashref;
+
+if ($pass) {
+print ">>>>" . $pass . "\n";
+print "  ok?\n";
+}
+
   if ($sth_pass->rows != 1) { 
     if (uc($billing_action) ne "REJECT") {
-      my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
-        values ('warning', concat('billing_server: logical_card_id ', ?, ', billing_cksum ', ?, ', art seq_num ', ?, ', dropping billing entry: no matching pass entry') ) ");
+      my $sth;
+      if ($isMySQL) {
+        $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+          values ('warning', concat('billing_server: logical_card_id ', ?, ', billing_cksum ', ?, ', art seq_num ', ?, ', dropping billing entry: no matching pass entry') ) ");
+      } else {
+        $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+          values ('warning', 'billing_server: logical_card_id ' ||  ? ||  ', billing_cksum ' || ? || ', art seq_num ' ||  ? || ', dropping billing entry: no matching pass entry' ) ");
+      }
       $sth->execute($logical_card_id, $billing_cksum, $oldrow[8]);
     }
     $dbh->commit; 
     return; 
   }
 
-  my $pass = $sth_pass->fetchrow_hashref;
+print "#bill: advance: cp2\n";
+
+  #my $pass = $sth_pass->fetchrow_hashref;
 
   my $t = $dbh->prepare("select ruleclass from rule_class where rulename = ?");
   $t->execute($pass->{'rule'});
+
+  my $tref = $t->fetchrow_hashref;
+
+print ">>> \$t->rows " . $t->rows . "\n";
+
   my $rule_class = 'OTHER';
   if ($t->rows == 1) { 
-    $rule_class = $t->fetchrow_hashref->{'ruleclass'}; 
+    #$rule_class = $t->fetchrow_hashref->{'ruleclass'}; 
+    $rule_class = $tref->{'ruleclass'}; 
   } elsif ($t->rows < 1) {
-    my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
-      values ('warning', concat('billing_server: logical_card_id ', ?, ', billing_cksum ', ?, ', art seq_num ', ?, ', no rule class found, dropping billing entry') ) ");
+    my $sth;
+    if ($isMySQL) {
+      my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+        values ('warning', concat('billing_server: logical_card_id ', ?, ', billing_cksum ', ?, ', art seq_num ', ?, ', no rule class found, dropping billing entry') ) ");
+    } else {
+      my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+        values ('warning', 'billing_server: logical_card_id ' || ? || ', billing_cksum ' || ? || ', art seq_num ' || ? || ', no rule class found, dropping billing entry' ) ");
+    }
     $sth->execute($logical_card_id, $billing_cksum, $oldrow[8]);
     $dbh->commit; 
     return; 
   } else {
-    my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
-      values ('warning', concat('billing_server: logical_card_id ', ?, ', billing_cksum ', ?, ', art seq_num ', ?, ', multiple rule classes found, dropping billing entry') ) ");
+    my $sth;
+    if ($isMySQL) {
+      my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+        values ('warning', concat('billing_server: logical_card_id ', ?, ', billing_cksum ', ?, ', art seq_num ', ?, ', multiple rule classes found, dropping billing entry') ) ");
+    } else {
+      my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+        values ('warning', 'billing_server: logical_card_id ' || ? || ', billing_cksum ' || ? || ', art seq_num ' || ? || ', multiple rule classes found, dropping billing entry' ) ");
+    }
     $sth->execute($logical_card_id, $billing_cksum, $oldrow[8]);
     $dbh->commit; 
     return; 
   }
 
+print "#bill: advance: cp3\n";
+
   if (uc($billing_action) eq "REJECT") {
     # bus not sync'd? 
     $dbh->commit;
   } elsif ($oldrow[3] ne $pass->{'rule'}) {
     # raise warning?
-    my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
-      values ('warning', concat('billing_server: logical_card_id ',?,', billing_cksum ',?,', art seq_num ',?,', rule mismatch(1): art rule \"',?,'\" != user_pass_id ',?,' rule \"',?,'\"') )");
+    my $sth;
+    if ($isMySQL) {
+      my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+        values ('warning', concat('billing_server: logical_card_id ',?,', billing_cksum ',?,', art seq_num ',?,', rule mismatch(1): art rule \"',?,'\" != user_pass_id ',?,' rule \"',?,'\"') )");
+    } else {
+      my $sth = $dbh->prepare("insert into diagnostic_log (loglvl, message) 
+        values ('warning', 'billing_server: logical_card_id ' || ? || ', billing_cksum ' || ? || ', art seq_num ' || ? || ', rule mismatch(1): art rule \"' || ? || '\" != user_pass_id ' || ? || ' rule \"' || ? || '\"' )");
+    }
     $sth->execute($logical_card_id, $billing_cksum, $oldrow[8], $oldrow[3], $pass->{'user_pass_id'}, $pass->{'rule'});
     $dbh->commit;
   } elsif ($billing_rule ne $pass->{'rule'}) {
@@ -333,36 +421,58 @@ sub AdvanceRiderPass {
 
     # expire passes will take care of it if #rides == 0
     if ($cur_rides>0) {
-      $q = $dbh->prepare("lock tables active_rider_table write");
-      $q->execute();
+      if ($isMySQL) {
+        $q = $dbh->prepare("lock tables active_rider_table write");
+        $q->execute();
+      }
       $q = $dbh->prepare('insert into active_rider_table (logical_card_id, rfid_token, mag_token, rule_name, rule_param, deleted, parent_entity, notes) 
         values (?, ?, ?,?, ?, ?, ?, ?)');
       $q->execute(@oldrow[0..7]);
     }
     $dbh->commit;
-    if ($cur_rides>0) { $q = $dbh->prepare("unlock tables"); $q->execute(); }
+    if ($cur_rides>0) {
+      if ($isMySQL) {
+        $q = $dbh->prepare("unlock tables");
+        $q->execute();
+      }
+    }
 
   } elsif ($rule_class eq 'NDAY') {
 
+print "#>> nday expiration " . $pass->{'nday_expiration'} . "\n";
+
     # update user_pass with expiration and update active_rider_table with new param
     if (!$pass->{'nday_expiration'}) {
       my $audit_pass_id = audit_user_pass_start($dbh, $pass->{'user_pass_id'}, "billing_server: AdvanceRiderPass: updating nday");
-      my $q = $dbh->prepare("update user_pass 
-                                set nday_expiration = addtime( adddate(convert(date(?), datetime), nday_orig), '2:30'), firstused = ?, lastused = ? 
-                              where user_pass_id = ?");
-      $q->execute($billing_ride_time, $billing_ride_time, $billing_ride_time, $pass->{'user_pass_id'});
+
+      my $q;
+      if ($isMySQL) {
+        my $q = $dbh->prepare("update user_pass 
+                                  set nday_expiration = addtime( adddate(convert(date(?), datetime), nday_orig), '2:30'), firstused = ?, lastused = ? 
+                                where user_pass_id = ?");
+        $q->execute($billing_ride_time, $billing_ride_time, $billing_ride_time, $pass->{'user_pass_id'});
+      } else {
+        my $q = $dbh->prepare("update user_pass 
+                                  set nday_expiration = strftime('%Y-%m-%d %H:%M:%S', date(?, '+? days'), '+150 minutes'), firstused = ?, lastused = ? 
+                                where user_pass_id = ?");
+        $q->execute($billing_ride_time, $billing_ride_time, $billing_ride_time, $pass->{'user_pass_id'});
+      }
       audit_user_pass_end($dbh, $pass->{'user_pass_id'}, $audit_pass_id);
 
       $oldrow[4] = $pass->{'nday_orig'} . " " . join('-', Add_Delta_Days(Today, $pass->{'nday_orig'} )) . " 2:30:00";
 
-      $q = $dbh->prepare("lock tables active_rider_table write"); $q->execute();
+      if ($isMySQL) {
+        $q = $dbh->prepare("lock tables active_rider_table write"); $q->execute();
+      }
       my $sth_new_expires = $dbh->prepare('INSERT INTO active_rider_table (logical_card_id, rfid_token, mag_token, rule_name, rule_param, deleted, parent_entity, notes) 
         VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
       $sth_new_expires->execute(@oldrow[0..7]);
 
       $dbh->commit;
-      $q = $dbh->prepare("unlock tables");
-      $q->execute();
+      if ($isMySQL) {
+        $q = $dbh->prepare("unlock tables");
+        $q->execute();
+      }
 
     } else {  # else just update last used
 
@@ -382,8 +492,11 @@ sub AdvanceRiderPass {
     $dbh->commit;
   }
 
+print "#bill: advance: cp4\n";
+
   ExpirePass( $dbh, $logical_card_id, $pass->{'user_pass_id'}, $billing_ride_time, @oldrow );
 
+print "#bill: advance: cp5\n";
 }
 
 sub ServerReply
@@ -415,11 +528,13 @@ sub ServerReply
 		$message =~  s/^.//;
 
 		try {
-			$sth = $dbh->prepare('INSERT IGNORE INTO diagnostic_log  (loglvl, message) VALUES (?, ?)')
+			$sth = $dbh->prepare('INSERT ' . ($isMySQL ? '' : ' OR ') . 'IGNORE INTO diagnostic_log  (loglvl, message) VALUES (?, ?)')
 				or die "Couldn't prepare statement: " . $dbh->errstr;
 	
 			$sth->execute($loglvl, $message)             # Execute the query
 				or die "Couldn't execute statement: " . $sth->errstr;
+
+      if (not $isMySQL) { $sth->fetch; }
 		}
 		catch {
 			$logmsg .= $_ . "\n";

+ 33 - 4
server/scripts/RideLogic.pm

@@ -82,14 +82,20 @@ our $RIDELOGIC_DAEMON_PID_DIR="./";
 
 our $RIDELOGIC_API_CONF="api.conf";
 
+our $RIDELOGIC_IS_SQLITE=1;
+
 sub audit_user_pass_start {
   my $dbh = shift;
   my $pass_id = shift;
   my $comment = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+
+  if ($isSqlite) { return -1; }
+
   my @field = qw( user_pass_id logical_card_id issued activated firstused lastused nrides_orig nrides_remain nday_orig nday_expiration active rule queue_order comment expired paytype deactivated );
   my $ins_query = " insert into audit_user_pass ( timestamp, comment, old_" . $field[0];
-  my $tail_ins_query = " select now(), ?, " . ($pass_id ? $field[0] : "null");
+  my $tail_ins_query = " select " . ($isSqlite ? "datetime('now', 'localtime')" : "now()") . ", ?, " . ($pass_id ? $field[0] : "null");
   for (my $i=1; $i<scalar(@field); $i++) {
     $ins_query .= ", old_" . $field[$i];
     $tail_ins_query .= ", " . ($pass_id ? $field[$i] : "null" );
@@ -108,7 +114,12 @@ sub audit_user_pass_end {
   my $pass_id = shift;
   my $audit_id = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+
+  if ($isSqlite) { return; }
+
   my @field = qw( user_pass_id logical_card_id issued activated firstused lastused nrides_orig nrides_remain nday_orig nday_expiration active rule queue_order comment expired paytype deactivated );
+
   my $up_query = " update audit_user_pass, user_pass set audit_user_pass.new_" . $field[0] . " = user_pass." . $field[0];
   for (my $i=1; $i<scalar(@field); $i++) {
     $up_query .= ", audit_user_pass.new_".$field[$i] . " = user_pass." . $field[$i];
@@ -125,9 +136,12 @@ sub audit_user_card_start {
   my $card_id = shift;
   my $comment = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+  if ($isSqlite) { return -1; }
+
   my @field = qw( logical_card_id mag_token rfid_token comment lastused userid issued firstused group_id active deactivated issuetype );
   my $ins_query = " insert into audit_user_card ( timestamp, comment, old_" . $field[0];
-  my $tail_ins_query = " select now(), ?, " . ($card_id ? $field[0] : "null");
+  my $tail_ins_query = " select  " . ($isSqlite ? "datetime('now', 'localtime')" : "now()") . ", ?, " . ($card_id ? $field[0] : "null");
   for (my $i=1; $i<scalar(@field); $i++) {
     $ins_query .= ", old_" . $field[$i];
     $tail_ins_query .= ", " . ($card_id ? $field[$i] : "null");
@@ -146,6 +160,9 @@ sub audit_user_card_end {
   my $card_id = shift;
   my $audit_id = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+  if ($isSqlite) { return; }
+
   my @field = qw( logical_card_id mag_token rfid_token comment lastused userid issued firstused group_id active deactivated issuetype );
   my $up_query = " update audit_user_card, user_card set audit_user_card.new_" . $field[0] . " = user_card." . $field[0];
   for (my $i=1; $i<scalar(@field); $i++) {
@@ -163,10 +180,13 @@ sub audit_users_start {
   my $userid = shift;
   my $comment = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+  if ($isSqlite) { return -1; }
+
   my @field = qw( username passwordhash userid comment first_name last_name phone email address city state zip created active
                   shipping_address shipping_city shipping_state shipping_zip shipping_name shipping_country_code shipping_country_name reset_attempts );
   my $ins_query = " insert into audit_users ( timestamp, comment, old_" . $field[0];
-  my $tail_ins_query = " select now(), ?, " . ($userid ? $field[0] : "null");
+  my $tail_ins_query = " select " . ($isSqlite ? "datetime('now', 'localtime')" : "now()") . ", ?, " . ($userid ? $field[0] : "null");
   for (my $i=1; $i<scalar(@field); $i++) {
     $ins_query .= ", old_".$field[$i];
     $tail_ins_query .= ", " . ($userid ? $field[$i] : "null");
@@ -185,6 +205,9 @@ sub audit_users_end {
   my $userid = shift;
   my $audit_id = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+  if ($isSqlite) { return; }
+
   my @field = qw( username passwordhash userid comment first_name last_name phone email address city state zip created active
                   shipping_address shipping_city shipping_state shipping_zip shipping_name shipping_country_code shipping_country_name reset_attempts );
   my $up_query = " update audit_users,  users set audit_users.new_" . $field[0] . " = users." . $field[0];
@@ -203,9 +226,12 @@ sub audit_admins_start {
   my $userid = shift;
   my $comment = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+  if ($isSqlite) { return -1; }
+
   my @field = qw( username password userid );
   my $ins_query = " insert into audit_admins ( timestamp, comment, old_" . $field[0];
-  my $tail_ins_query = " select now(), ?, " . ($userid ? $field[0] : "null");
+  my $tail_ins_query = " select " . ($isSqlite ? "datetime('now', 'localtime')" : "now()") . ", ?, " . ($userid ? $field[0] : "null");
   for (my $i=1; $i<scalar(@field); $i++) {
     $ins_query .= ", old_".$field[$i];
     $tail_ins_query .= ", " . ($userid ? $field[$i] : "null");
@@ -224,6 +250,9 @@ sub audit_admins_end {
   my $userid = shift;
   my $audit_id = shift;
 
+  my $isSqlite = $RIDELOGIC_IS_SQLITE;
+  if ($isSqlite) { return;  }
+
   my @field = qw( username password userid );
   my $up_query = " update audit_admins,  admins set audit_admins.new_" . $field[0] . " = admins." . $field[0];
   for (my $i=1; $i<scalar(@field); $i++) {

+ 2 - 1
server/sql_schema/create_tables.sql

@@ -90,7 +90,8 @@ CREATE TABLE IF NOT EXISTS billing_log (
 
 
 CREATE TABLE IF NOT EXISTS diagnostic_log (
-  servertime TIMESTAMP NOT NULL,
+  id INT PRIMARY KEY,
+  servertime TIMESTAMP default CURRENT_TIMESTAMP,
   loglvl VARCHAR(8),
   message VARCHAR(256),
 

+ 11 - 2
server/sql_schema/create_tables.sqlite

@@ -51,7 +51,12 @@ CREATE TABLE IF NOT EXISTS active_rider_table (
 
   -- The rest are for server-side recordkeeping...
 
-  deleted BOOLEAN DEFAULT '0'
+  deleted BOOLEAN DEFAULT '0',
+
+  parent_entity VARCHAR(32),
+  notes  VARCHAR(64)
+
+
 ) ;
 
 create INDEX active_rider_table_seq_idx on active_rider_table (seq_num);
@@ -94,7 +99,7 @@ CREATE TABLE IF NOT EXISTS billing_log (
 CREATE TABLE IF NOT EXISTS diagnostic_log (
   id INTEGER PRIMARY KEY,
 
-  servertime TIMESTAMP NOT NULL,
+  servertime TIMESTAMP default CURRENT_TIMESTAMP,
   loglvl VARCHAR(8),
   message VARCHAR(256)
 
@@ -243,6 +248,8 @@ CREATE TABLE `audit_user_pass` (
   `old_user_pass_id` INTEGER default NULL,
   `old_logical_card_id` INTEGER default NULL,
   `old_issued` datetime default NULL,
+  `old_activated` datetime default NULL,
+  `old_deactivated` datetime default NULL,
   `old_firstused` datetime default NULL,
   `old_lastused` datetime default NULL,
   `old_nrides_orig` INTEGER default NULL,
@@ -257,6 +264,8 @@ CREATE TABLE `audit_user_pass` (
   `new_user_pass_id` INTEGER default NULL,
   `new_logical_card_id` INTEGER default NULL,
   `new_issued` datetime default NULL,
+  `new_activated` datetime default NULL,
+  `new_deactivated` datetime default NULL,
   `new_firstused` datetime default NULL,
   `new_lastused` datetime default NULL,
   `new_nrides_orig` INTEGER default NULL,

+ 10 - 10
server/testing/db/setup-testdb.sqlite

@@ -52,22 +52,22 @@ insert  into user_card
   values
 
   (1, '2:7370000000007015', '26:137:677', 'testing card 0',
-   datetime(), 1,
+   datetime('now', 'localtime'), 1,
    NULL, NULL, NULL,
    73576, NULL),
 
   (2, '2:65465412301', '26:250:8002', 'testing card 1',
-   datetime(), 1,
+   datetime('now', 'localtime'), 1,
    NULL, NULL, NULL,
    73577, NULL),
 
   (3, '2:255100010170331', '35:507:100569', 'testing card 2',
-   datetime(), 1,
+   datetime('now', 'localtime'), 1,
    NULL, NULL, NULL,
    73578, NULL),
 
   (4, '3:7100306127', NULL, 'testing card 3',
-   datetime(), 1,
+   datetime('now', 'localtime'), 1,
    NULL, NULL, NULL,
    73579, NULL)
 ;
@@ -86,23 +86,23 @@ insert  into user_pass
 
   -- card 1 passes (nride then nday)
   (11, 1,
-   datetime(), datetime(), NULL,
+   datetime('now', 'localtime'), datetime('now', 'localtime'), NULL,
    NULL, NULL,
    5, 5,
    NULL, NULL,
    1, 0,
    'TEST-ORG-NRIDE', 1, 'Test pass', NULL),
   (12, 1,
-   datetime(), datetime(), NULL,
+   datetime('now', 'localtime'), datetime('now', 'localtime'), NULL,
    NULL, NULL,
    NULL, NULL,
    15, NULL,
-   1, 0,
+   0, 0,
    'TEST-ORG-NDAY', 2, 'Test pass', NULL),
 
   -- card 2 passes
   (13, 2,
-   datetime(), datetime(), NULL,
+   datetime('now', 'localtime'), datetime('now', 'localtime'), NULL,
    NULL, NULL,
    NULL, NULL,
    NULL, NULL,
@@ -111,7 +111,7 @@ insert  into user_pass
 
   -- card 3 passes
   (14, 3,
-   datetime(), datetime(), NULL,
+   datetime('now', 'localtime'), datetime('now', 'localtime'), NULL,
    NULL, NULL,
    NULL, NULL,
    NULL, NULL,
@@ -120,7 +120,7 @@ insert  into user_pass
 
   -- card 4 passes
   (15, 4,
-   datetime(), datetime(), NULL,
+   datetime('now', 'localtime'), datetime('now', 'localtime'), NULL,
    NULL, NULL,
    NULL, NULL,
    NULL, NULL,