Exemple #1
0
     AddTableField('build', 'buildduration', 'int(11)', 'integer', '0');
     UpgradeBuildDuration();
 }
 // Support for marking a build as "done".
 AddTableField('build', 'done', 'tinyint(1)', 'smallint', '0');
 // Add a unique uuid field to the build table.
 $uuid_check = pdo_query('SELECT uuid FROM build LIMIT 1');
 if ($uuid_check === false) {
     AddTableField('build', 'uuid', 'varchar(36)', 'character varying(36)', false);
     if ($db_type === 'pgsql') {
         pdo_query('ALTER TABLE build ADD UNIQUE (uuid)');
     } else {
         pdo_query('ALTER TABLE build ADD UNIQUE KEY (uuid)');
     }
     // Also add a new unique constraint to the site table.
     AddUniqueConstraintToSiteTable('site');
     // Also add a new unique constraint to the subproject table.
     if ($db_type === 'pgsql') {
         pdo_query('ALTER TABLE subproject ADD UNIQUE (name, projectid, endtime)');
         pdo_query('CREATE INDEX "subproject_unique2" ON "subproject" ("name", "projectid", "endtime")');
     } else {
         pdo_query('ALTER TABLE subproject ADD UNIQUE KEY (name, projectid, endtime)');
     }
 }
 // Support for subproject path.
 AddTableField('subproject', 'path', 'varchar(512)', 'character varying(512)', '');
 // Remove the errorlog from the DB (we're all log files now).
 pdo_query('DROP TABLE IF EXISTS errorlog');
 // Option to pass label filters from index.php to test pages.
 AddTableField('project', 'sharelabelfilters', 'tinyint(1)', 'smallint', '0');
 // Summarize the number of dynamic analysis defects each build found.
Exemple #2
0
 public function testSiteConstraintUpgrade()
 {
     require_once dirname(__FILE__) . '/cdash_test_case.php';
     require_once 'include/common.php';
     require_once 'include/pdo.php';
     $retval = 0;
     $table_name = 'testsite';
     global $CDASH_DB_TYPE;
     if ($CDASH_DB_TYPE == 'pgsql') {
         $create_query = '
             CREATE TABLE "' . $table_name . '" (
                     "id" serial NOT NULL,
                     "name" character varying(255) DEFAULT \'\' NOT NULL,
                     "ip" character varying(255) DEFAULT \'\' NOT NULL,
                     "latitude" character varying(10) DEFAULT \'\' NOT NULL,
                     "longitude" character varying(10) DEFAULT \'\' NOT NULL,
                     "outoforder" smallint DEFAULT \'0\' NOT NULL,
                     PRIMARY KEY ("id")
                     )';
     } else {
         // MySQL
         $create_query = "\n                CREATE TABLE `{$table_name}` (\n                        `id` int(11) NOT NULL auto_increment,\n                        `name` varchar(255) NOT NULL default '',\n                        `ip` varchar(255) NOT NULL default '',\n                        `latitude` varchar(10) NOT NULL default '',\n                        `longitude` varchar(10) NOT NULL default '',\n                        `outoforder` tinyint(4) NOT NULL default '0',\n                        PRIMARY KEY  (`id`)\n                        )";
     }
     // Create testing table.
     if (!pdo_query($create_query)) {
         $this->fail('pdo_query returned false');
         $retval = 1;
     }
     // Find the largest siteid from the real site table.
     $row = pdo_single_row_query('SELECT id FROM site ORDER BY id DESC LIMIT 1');
     $i = $row['id'];
     $dupes = array();
     $keepers = array();
     // Insert sites into our testing table that will violate
     // the (name, ip) unique constraint.
     //
     // Case 1: No lat/lon info, so the lowest number siteid will be kept.
     $nolatlon_keeper = ++$i;
     $keepers[] = $nolatlon_keeper;
     $insert_query = "\n            INSERT INTO {$table_name}\n            (id, name, ip)\n            VALUES\n            ({$nolatlon_keeper}, 'case1_site', '128.4.4.1')";
     if (!pdo_query($insert_query)) {
         $this->fail('pdo_query returned false');
         $retval = 1;
     }
     $nolatlon_dupe = ++$i;
     $dupes[] = $nolatlon_dupe;
     $insert_query = "\n            INSERT INTO {$table_name}\n            (id, name, ip)\n            VALUES\n            ({$nolatlon_dupe}, 'case1_site', '128.4.4.1')";
     if (!pdo_query($insert_query)) {
         $this->fail('pdo_query returned false');
         $retval = 1;
     }
     // Case 2: Lat/lon info is present, so the newest build with this data
     // will be kept.
     $latlon_dupe1 = ++$i;
     // Has lat/lon, but not the newest.
     $dupes[] = $latlon_dupe1;
     $insert_query = "\n            INSERT INTO {$table_name}\n            (id, name, ip, latitude, longitude)\n            VALUES\n            ({$latlon_dupe1}, 'case2_site', '129.5.5.2', '40.70', '-74.00')";
     if (!pdo_query($insert_query)) {
         $this->fail('pdo_query returned false');
         $retval = 1;
     }
     $latlon_keeper = ++$i;
     // Has newest lat/lon, will be kept.
     $keepers[] = $latlon_keeper;
     $insert_query = "\n            INSERT INTO {$table_name}\n            (id, name, ip, latitude, longitude)\n            VALUES\n            ({$latlon_keeper}, 'case2_site', '129.5.5.2', '40.71', '-73.97')";
     if (!pdo_query($insert_query)) {
         $this->fail('pdo_query returned false');
         $retval = 1;
     }
     $latlon_dupe2 = ++$i;
     // Does not have lat/lon.
     $dupes[] = $latlon_dupe2;
     $insert_query = "\n            INSERT INTO {$table_name}\n            (id, name, ip)\n            VALUES\n            ({$latlon_dupe2}, 'case2_site', '129.5.5.2')";
     if (!pdo_query($insert_query)) {
         $this->fail('pdo_query returned false');
         $retval = 1;
     }
     // We also need to verify that siteids in other tables get updated
     // properly as duplicates are removed.
     $tables_to_update = array('build', 'build2grouprule', 'site2user', 'client_job', 'client_site2cmake', 'client_site2compiler', 'client_site2library', 'client_site2program', 'client_site2project');
     foreach ($tables_to_update as $table_to_update) {
         foreach ($dupes as $dupe) {
             if ($table_to_update === 'build') {
                 // Handle unique constraint here.
                 $insert_query = "INSERT INTO {$table_to_update} (siteid, uuid)\n                        VALUES ({$dupe}, '{$dupe}')";
             } elseif ($table_to_update === 'client_job') {
                 $insert_query = "INSERT INTO {$table_to_update} (siteid, scheduleid, osid, cmakeid, compilerid)\n                        VALUES ({$dupe}, 0, 0, 0, 0)";
             } elseif ($table_to_update === 'client_site2compiler') {
                 $insert_query = "INSERT INTO {$table_to_update} (siteid, generator)\n                        VALUES ({$dupe}, 'asdf')";
             } elseif ($table_to_update === 'client_site2library') {
                 $insert_query = "INSERT INTO {$table_to_update} (siteid, include)\n                        VALUES ({$dupe}, 'asdf')";
             } elseif ($table_to_update === 'client_site2program') {
                 $insert_query = "INSERT INTO {$table_to_update} (siteid, name, version, path)\n                        VALUES ({$dupe}, 'asdf', 'asdf', 'asdf')";
             } else {
                 $insert_query = "INSERT INTO {$table_to_update} (siteid) VALUES ({$dupe})";
             }
             if (!pdo_query($insert_query)) {
                 $this->fail('pdo_query returned false');
                 $retval = 1;
             }
         }
     }
     // Run the upgrade function.
     AddUniqueConstraintToSiteTable($table_name);
     // Verify that all of the keepers still exist.
     foreach ($keepers as $keeper) {
         $count_query = "\n                SELECT COUNT(id) AS numsites FROM {$table_name} WHERE id={$keeper}";
         $count_results = pdo_single_row_query($count_query);
         if ($count_results['numsites'] != 1) {
             $this->fail('Expected 1 site, found ' . $count_results['numsites']);
             $retval = 1;
         }
     }
     // Verify that none of the duplicates still exist.
     foreach ($dupes as $dupe) {
         $count_query = "\n                SELECT COUNT(id) AS numsites FROM {$table_name} WHERE id={$dupe}";
         $count_results = pdo_single_row_query($count_query);
         if ($count_results['numsites'] != 0) {
             $this->fail('Expected 0 site, found ' . $count_results['numsites']);
             $retval = 1;
         }
     }
     // Verify that the other references were also updated properly.
     foreach ($tables_to_update as $table_to_update) {
         foreach ($keepers as $keeper) {
             $expected_matches = 1;
             if ($keeper === $latlon_keeper) {
                 $expected_matches = 2;
             }
             $count_query = "SELECT COUNT(siteid) AS numsites\n                    FROM {$table_to_update} WHERE siteid={$keeper}";
             $count_results = pdo_single_row_query($count_query);
             if ($count_results['numsites'] != $expected_matches) {
                 $this->fail("Expected {$expected_matches} match for siteid {$keeper}\n                            in {$table_to_update}, found " . $count_results['numsites']);
                 $retval = 1;
             }
         }
         foreach ($dupes as $dupe) {
             $count_query = "SELECT COUNT(siteid) AS numsites\n                    FROM {$table_to_update} WHERE siteid={$dupe}";
             $count_results = pdo_single_row_query($count_query);
             if ($count_results['numsites'] != 0) {
                 $this->fail("Expected 0 matches for siteid {$dupe}\n                            in {$table_to_update}, found " . $count_results['numsites']);
                 $retval = 1;
             }
         }
     }
     // Remove any testing data that we inserted in the existing tables.
     foreach ($tables_to_update as $table_to_update) {
         foreach ($keepers as $keeper) {
             pdo_query("DELETE FROM {$table_to_update} WHERE siteid={$keeper}");
         }
         foreach ($dupes as $dupe) {
             pdo_query("DELETE FROM {$table_to_update} WHERE siteid={$dupe}");
         }
     }
     // Drop the testing table.
     pdo_query("DROP TABLE {$table_name}");
     if ($retval == 0) {
         $this->pass('Passed');
     }
     return $retval;
 }