Переглянути джерело

testing scripts/sql for test DB in docker container

clementinecomputing 6 роки тому
батько
коміт
d096fe9c09

+ 16 - 2
server/docker/Dockerfile

@@ -11,7 +11,8 @@ RUN \
   apt-get install -y gcc perl \
     git openssh-server sqlite3 libdbd-sqlite3-perl \
     default-mysql-server apache2 \
-    netcat telnet wget
+    netcat telnet wget \
+    mariadb-server
 
 RUN \
   apt-get install -y libswitch-perl libdate-calc-perl
@@ -23,7 +24,20 @@ RUN \
 RUN \
   su bus -c " cd /home/bus && \
     git clone https://tree.clementinecomputing.com/clementinecomputing/popufare && \
-    mkdir -p /home/bus/.ssh && chmod 0700 /home/bus/.ssh "
+    mkdir -p /home/bus/.ssh && chmod 0700 /home/bus/.ssh && \
+    mkdir -p /home/bus/bin && \
+    mkdir -p /home/bus/data && \
+      sqlite3 /home/bus/data/bus.sqlite < /home/bus/popufare/server/sql_schema/create_tables.sqlite && \
+      sqlite3 /home/bus/data/bus.sqlite < /home/bus/popufare/server/testing/db/setup-testdb.sqlite "
+
+COPY setup-testdb /root/setup-testdb
+
+RUN bash /root/setup-testdb
+#  service mysql start && \
+#  bash -c 'mysql < <( echo -e "create database busdb;\ncreate user bus;\ngrant all privileges on busdb.* to \'bus\'@\'%\';\nflush privileges;\n" ) ' && \
+#  su bus -c " cd /home/bus && \
+#    mysql -u bus busdb < popufare/server/create_tables.sql && \
+#    mysql -u bus busdb < popufare/server/testing/db/setup-testdb.sql "
 
 ## setup test ssh access
 ##

+ 8 - 0
server/docker/setup-testdb

@@ -0,0 +1,8 @@
+#!/bin/bash
+
+service mysql start && \
+  mysql < <( echo -e 'create database busdb;\ncreate user bus;\ngrant all privileges on busdb.* to "bus"@"%";\nflush privileges;\n' ) && \
+  su bus -c " cd /home/bus && \
+    mysql -u bus busdb < /home/bus/popufare/server/sql_schema/create_tables.sql && \
+    mysql -u bus busdb < popufare/server/testing/db/setup-testdb.sql "
+

+ 36 - 19
server/sql_schema/create_tables.sql

@@ -19,7 +19,7 @@
 
 -- AVLS data table receives all AVLS chirps and stores them for later reference
 CREATE TABLE IF NOT EXISTS avls_data (
-
+  id bigint auto_increment primary key,
   equip_num INT,
   driver INT,
   paddle INT,
@@ -31,7 +31,6 @@ CREATE TABLE IF NOT EXISTS avls_data (
   longitude DOUBLE,
   heading DOUBLE,
   velocity DOUBLE
-
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- Bus Pass Table holds all bus pass holders
@@ -63,6 +62,7 @@ CREATE TABLE IF NOT EXISTS active_rider_table (
 
 -- DROP TABLE IF EXISTS `billing_log`;
 CREATE TABLE IF NOT EXISTS billing_log (
+  id bigint auto_increment primary key,
 
   -- MD5 sum of the orignal record as sent by the client, used to confirm storing the record
   conf_checksum VARCHAR(32) UNIQUE,
@@ -90,7 +90,7 @@ CREATE TABLE IF NOT EXISTS billing_log (
 
 
 CREATE TABLE IF NOT EXISTS diagnostic_log (
-  id INT PRIMARY KEY,
+  id bigINT auto_increment PRIMARY KEY,
   servertime TIMESTAMP default CURRENT_TIMESTAMP,
   loglvl VARCHAR(8),
   message VARCHAR(256),
@@ -102,8 +102,9 @@ CREATE TABLE IF NOT EXISTS diagnostic_log (
   
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-create table pass_option
-( id int not null auto_increment,
+drop table if exists pass_option;
+create table pass_option (
+  id bigint auto_increment primary key,
   group_id    int,
   param       int,
   name        varchar(255),
@@ -117,14 +118,15 @@ create table pass_option
   option2     varchar(255),
   option3     varchar(255),
   
-  active      tinyint default 0,
+  active      tinyint default 0
   
-  primary key (id),
-  unique key id (id)
+  -- primary key (id),
+  -- unique key id (id)
 ) engine=InnoDB ;
 
 
 CREATE TABLE IF NOT EXISTS rule_class (
+  id bigint auto_increment primary key,
   rulename VARCHAR(24),
   ruleclass VARCHAR(24)
   
@@ -139,7 +141,8 @@ CREATE TABLE IF NOT EXISTS update_level (
   fileversion VARCHAR(32),
   
   -- The following field is never manually set and is used only to pull the latest value
-  serial BIGINT NOT NULL AUTO_INCREMENT,
+  -- serial BIGINT NOT NULL AUTO_INCREMENT,
+  serial BIGINT AUTO_INCREMENT primary key,
 
   -- These indicies should make the operation of "give me the latest of each update for bus number X" fast  
   
@@ -151,6 +154,7 @@ CREATE TABLE IF NOT EXISTS update_level (
 )ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 CREATE TABLE IF NOT EXISTS bus_checkin_log (
+  id bigint auto_increment primary key,
    checkin_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    busunit_num INT NOT NULL DEFAULT 0,
    equip_num INT NOT NULL DEFAULT 0,
@@ -236,6 +240,7 @@ CREATE TABLE `user_card` (
 
 DROP TABLE IF EXISTS `groups`;
 CREATE TABLE `groups` (
+  id bigint auto_increment primary key,
   group_id int(11) default NULL,
   group_name varchar(255) default NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -450,21 +455,25 @@ CREATE TABLE `audit_admins` (
 
 DROP TABLE IF EXISTS `admins_session_info`;
 CREATE TABLE `admins_session_info` (
+  `id` int not null auto_increment,
           `userid` int(255) default NULL,
           `sessionid` char(255) default NULL,
-          `lastactive` datetime default NULL
+          `lastactive` datetime default NULL,
+          PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 DROP TABLE IF EXISTS `admin_groups`;
 CREATE TABLE `admin_groups` (
+  `id` int not null auto_increment,
           `userid` int(127) default NULL,
           `group_id` int(11) default NULL,
-          `permissions` int(127) default NULL
+          `permissions` int(127) default NULL,
+          PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 DROP TABLE IF EXISTS `rule_mappings`;
 CREATE TABLE `rule_mappings` (
-  `id` int not null,
+  `id` int not null auto_increment,
           `rule` char(255) NOT NULL default '',
           `rule_text` char(255) default NULL,
           `group_id` int(11) default NULL,
@@ -525,6 +534,7 @@ CREATE TABLE `org_card_order_queue` (
 
 DROP TABLE IF EXISTS `org_api_session`;
 CREATE TABLE `org_api_session` (
+  id bigint auto_increment primary key,
           `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
           `ip` varchar(15) default NULL,
           `active` tinyint(4) default NULL,
@@ -542,6 +552,7 @@ CREATE TABLE `org_api_log` (
 
 DROP TABLE IF EXISTS `org_api_password_reset`;
 CREATE TABLE `org_api_password_reset` (
+  id bigint auto_increment primary key,
           `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
           `token` varchar(255) default NULL,
           `userid` int(11) default NULL,
@@ -551,6 +562,7 @@ CREATE TABLE `org_api_password_reset` (
 
 DROP TABLE IF EXISTS `org_api_register_email`;
 CREATE TABLE `org_api_register_email` (
+  id bigint auto_increment primary key,
           `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
           `token` varchar(255) default NULL,
           `active` tinyint(1) default NULL,
@@ -597,7 +609,8 @@ DROP TABLE IF EXISTS `paddles`;
 SET @saved_cs_client     = @@character_set_client;
 SET character_set_client = utf8;
 CREATE TABLE `paddles` (
-  `id` int(11) NOT NULL default '0',
+  -- `id` int(11) NOT NULL default '0',
+  `id` bigint auto_increment primary key,
   `slot` int(11) NOT NULL default '0',
   `arrival` time default NULL,
   `route` int(11) default NULL,
@@ -618,7 +631,8 @@ SET @saved_cs_client     = @@character_set_client;
 SET character_set_client = utf8;
 CREATE TABLE `old_stops` (
   `verstring` text,
-  `id` int(11) NOT NULL default '0',
+  -- `id` int(11) NOT NULL default '0',
+  `id` bigint auto_increment primary key,
   `latitude` double NOT NULL default '0',
   `longitude` double NOT NULL default '0',
   `name` varchar(32) default NULL
@@ -634,7 +648,8 @@ SET @saved_cs_client     = @@character_set_client;
 SET character_set_client = utf8;
 CREATE TABLE `old_paddles` (
   `verstring` text,
-  `id` int(11) NOT NULL default '0',
+  -- `id` int(11) NOT NULL default '0',
+  `id` bigint auto_increment primary key,
   `slot` int(11) NOT NULL default '0',
   `arrival` time default NULL,
   `route` int(11) default NULL,
@@ -670,7 +685,8 @@ DROP TABLE IF EXISTS `live_paddles`;
 SET @saved_cs_client     = @@character_set_client;
 SET character_set_client = utf8;
 CREATE TABLE `live_paddles` (
-  `id` int(11) NOT NULL default '0',
+  -- `id` int(11) NOT NULL default '0',
+  `id` bigint auto_increment primary key,
   `slot` int(11) NOT NULL default '0',
   `arrival` time default NULL,
   `route` int(11) default NULL,
@@ -687,7 +703,8 @@ DROP TABLE IF EXISTS `price_point`;
 SET @saved_cs_client     = @@character_set_client;
 SET character_set_client = utf8;
 CREATE TABLE `price_point` (
-  `id` int(11) NOT NULL auto_increment,
+  -- `id` int(11) NOT NULL auto_increment,
+  `id` bigint auto_increment primary key,
   `price` double default NULL,
   `param` int(11) default NULL,
   `name` varchar(255) default NULL,
@@ -710,8 +727,8 @@ drop table if exists billing_log_annotation;
 SET @saved_cs_client     = @@character_set_client;
 SET character_set_client = utf8;
 create table if not exists billing_log_annotation (
-  id int(11) unique not null auto_increment,
-  seq_num int not null,
+  id bigint unique not null,
+  seq_num bigint not null,
   rule varchar(24),
   ruleparam varchar(24),
   reason varchar(64),