Commit 26c0511c authored by Alexandre's avatar Alexandre
Browse files

Merge branch 'rename-column-to-fingerprint'

parents 069732ea 49ec9a08
......@@ -76,7 +76,7 @@ sub create_db {
priority integer DEFAULT 10,
queue integer DEFAULT 0,
progress integer DEFAULT 0,
params_deterministic_hash character varying(32),
fingerprint character varying(32),
params blob NOT NULL,
results mediumblob DEFAULT NULL,
undelegated integer NOT NULL DEFAULT 0,
......@@ -117,9 +117,9 @@ sub create_db {
'CREATE INDEX test_results__hash_id ON test_results (hash_id)'
);
}
if ( not exists($indexes->{test_results__params_deterministic_hash}) ) {
if ( not exists($indexes->{test_results__fingerprint}) ) {
$dbh->do(
'CREATE INDEX test_results__params_deterministic_hash ON test_results (params_deterministic_hash)'
'CREATE INDEX test_results__fingerprint ON test_results (fingerprint)'
);
}
if ( not exists($indexes->{test_results__batch_id_progress}) ) {
......@@ -243,7 +243,7 @@ sub create_new_test {
$dbh->do( q[LOCK TABLES test_results WRITE] );
my ( $recent_hash_id ) = $dbh->selectrow_array(
q[
SELECT hash_id FROM test_results WHERE params_deterministic_hash = ? AND (TO_SECONDS(NOW()) - TO_SECONDS(creation_time)) < ?
SELECT hash_id FROM test_results WHERE fingerprint = ? AND (TO_SECONDS(NOW()) - TO_SECONDS(creation_time)) < ?
],
undef, $fingerprint, $seconds_between_tests_with_same_params,
);
......@@ -255,7 +255,7 @@ sub create_new_test {
else {
$dbh->do(
q[
INSERT INTO test_results (batch_id, priority, queue, params_deterministic_hash, params, domain, test_start_time, undelegated) VALUES (?, ?,?,?,?,?, NOW(),?)
INSERT INTO test_results (batch_id, priority, queue, fingerprint, params, domain, test_start_time, undelegated) VALUES (?, ?,?,?,?,?, NOW(),?)
],
undef,
$batch_id,
......@@ -268,7 +268,7 @@ sub create_new_test {
);
my ( undef, $hash_id ) = $dbh->selectrow_array(
"SELECT id, hash_id FROM test_results WHERE params_deterministic_hash=? ORDER BY id DESC LIMIT 1", undef, $fingerprint);
"SELECT id, hash_id FROM test_results WHERE fingerprint=? ORDER BY id DESC LIMIT 1", undef, $fingerprint);
$result_id = $hash_id;
}
......@@ -438,12 +438,12 @@ sub add_batch_job {
$dbh->{AutoCommit} = 0;
eval {$dbh->do( "DROP INDEX test_results__hash_id ON test_results" );};
eval {$dbh->do( "DROP INDEX test_results__params_deterministic_hash ON test_results" );};
eval {$dbh->do( "DROP INDEX test_results__fingerprint ON test_results" );};
eval {$dbh->do( "DROP INDEX test_results__batch_id_progress ON test_results" );};
eval {$dbh->do( "DROP INDEX test_results__progress ON test_results" );};
eval {$dbh->do( "DROP INDEX test_results__domain_undelegated ON test_results" );};
my $sth = $dbh->prepare( 'INSERT INTO test_results (domain, batch_id, priority, queue, params_deterministic_hash, params, undelegated) VALUES (?, ?, ?, ?, ?, ?, ?) ' );
my $sth = $dbh->prepare( 'INSERT INTO test_results (domain, batch_id, priority, queue, fingerprint, params, undelegated) VALUES (?, ?, ?, ?, ?, ?, ?) ' );
foreach my $domain ( @{$params->{domains}} ) {
$test_params->{domain} = $domain;
......@@ -454,7 +454,7 @@ sub add_batch_job {
$sth->execute( $test_params->{domain}, $batch_id, $priority, $queue_label, $fingerprint, $encoded_params, $undelegated );
}
$dbh->do( "CREATE INDEX test_results__hash_id ON test_results (hash_id, creation_time)" );
$dbh->do( "CREATE INDEX test_results__params_deterministic_hash ON test_results (params_deterministic_hash)" );
$dbh->do( "CREATE INDEX test_results__fingerprint ON test_results (fingerprint)" );
$dbh->do( "CREATE INDEX test_results__batch_id_progress ON test_results (batch_id, progress)" );
$dbh->do( "CREATE INDEX test_results__progress ON test_results (progress)" );
$dbh->do( "CREATE INDEX test_results__domain_undelegated ON test_results (domain, undelegated)" );
......
......@@ -70,7 +70,7 @@ sub create_db {
priority integer DEFAULT 10,
queue integer DEFAULT 0,
progress integer DEFAULT 0,
params_deterministic_hash varchar(32),
fingerprint varchar(32),
params json NOT NULL,
undelegated integer NOT NULL DEFAULT 0,
results json,
......@@ -89,9 +89,9 @@ sub create_db {
'CREATE INDEX test_results__hash_id ON test_results (hash_id)'
);
}
if ( not exists($indexes->{test_results__params_deterministic_hash}) ) {
if ( not exists($indexes->{test_results__fingerprint}) ) {
$dbh->do(
'CREATE INDEX test_results__params_deterministic_hash ON test_results (params_deterministic_hash)'
'CREATE INDEX test_results__fingerprint ON test_results (fingerprint)'
);
}
if ( not exists($indexes->{test_results__batch_id_progress}) ) {
......@@ -223,11 +223,11 @@ sub create_new_test {
my $queue_label = $test_params->{queue};
my $sth = $dbh->prepare( "
INSERT INTO test_results (batch_id, priority, queue, params_deterministic_hash, params, undelegated)
INSERT INTO test_results (batch_id, priority, queue, fingerprint, params, undelegated)
SELECT ?, ?, ?, ?, ?, ?
WHERE NOT EXISTS (
SELECT * FROM test_results
WHERE params_deterministic_hash = ?
WHERE fingerprint = ?
AND creation_time > NOW() - ?::interval
)" );
my $nb_inserted = $sth->execute( #
......@@ -242,7 +242,7 @@ sub create_new_test {
);
my ( undef, $hash_id ) = $dbh->selectrow_array(
"SELECT id,hash_id FROM test_results WHERE params_deterministic_hash=? ORDER BY id DESC LIMIT 1", undef, $fingerprint );
"SELECT id,hash_id FROM test_results WHERE fingerprint=? ORDER BY id DESC LIMIT 1", undef, $fingerprint );
return $hash_id;
}
......@@ -380,12 +380,12 @@ sub add_batch_job {
$dbh->begin_work();
$dbh->do( "ALTER TABLE test_results DROP CONSTRAINT IF EXISTS test_results_pkey" );
$dbh->do( "DROP INDEX IF EXISTS test_results__hash_id" );
$dbh->do( "DROP INDEX IF EXISTS test_results__params_deterministic_hash" );
$dbh->do( "DROP INDEX IF EXISTS test_results__fingerprint" );
$dbh->do( "DROP INDEX IF EXISTS test_results__batch_id_progress" );
$dbh->do( "DROP INDEX IF EXISTS test_results__progress" );
$dbh->do( "DROP INDEX IF EXISTS test_results__domain_undelegated" );
$dbh->do( "COPY test_results(batch_id, priority, queue, params_deterministic_hash, params, undelegated) FROM STDIN" );
$dbh->do( "COPY test_results(batch_id, priority, queue, fingerprint, params, undelegated) FROM STDIN" );
foreach my $domain ( @{$params->{domains}} ) {
$test_params->{domain} = $domain;
......@@ -398,7 +398,7 @@ sub add_batch_job {
$dbh->pg_putcopyend();
$dbh->do( "ALTER TABLE test_results ADD PRIMARY KEY (id)" );
$dbh->do( "CREATE INDEX test_results__hash_id ON test_results (hash_id, creation_time)" );
$dbh->do( "CREATE INDEX test_results__params_deterministic_hash ON test_results (params_deterministic_hash)" );
$dbh->do( "CREATE INDEX test_results__fingerprint ON test_results (fingerprint)" );
$dbh->do( "CREATE INDEX test_results__batch_id_progress ON test_results (batch_id, progress)" );
$dbh->do( "CREATE INDEX test_results__progress ON test_results (progress)" );
$dbh->do( "CREATE INDEX test_results__domain_undelegated ON test_results ((params->>'domain'), (params->>'undelegated'))" );
......
......@@ -69,7 +69,7 @@ sub create_db {
priority integer DEFAULT 10,
queue integer DEFAULT 0,
progress integer DEFAULT 0,
params_deterministic_hash character varying(32),
fingerprint character varying(32),
params text NOT NULL,
results text DEFAULT NULL,
undelegated boolean NOT NULL DEFAULT false,
......@@ -81,8 +81,8 @@ sub create_db {
$dbh->do(
'CREATE INDEX IF NOT EXISTS test_results__hash_id ON test_results (hash_id)'
);
$dbh->do(
'CREATE INDEX IF NOT EXISTS test_results__fingerprint ON test_results (params_deterministic_hash)'
$self->dbh->do(
'CREATE INDEX IF NOT EXISTS test_results__fingerprint ON test_results (fingerprint)'
);
$dbh->do(
'CREATE INDEX IF NOT EXISTS test_results__batch_id_progress ON test_results (batch_id, progress)'
......@@ -199,7 +199,7 @@ sub create_new_test {
# Search for recent test result with the test same parameters, where "$seconds"
# gives the time limit for how old test result that is accepted.
my ( $recent_hash_id ) = $dbh->selectrow_array(
"SELECT hash_id FROM test_results WHERE params_deterministic_hash = ? AND test_start_time > DATETIME('now', ?)",
"SELECT hash_id FROM test_results WHERE fingerprint = ? AND test_start_time > DATETIME('now', ?)",
undef,
$fingerprint,
"-$seconds seconds"
......@@ -216,7 +216,7 @@ sub create_new_test {
# cannot, however, be guaranteed. Same as with the other database engines.
my $hash_id = substr(md5_hex(time().rand()), 0, 16);
my $fields = 'hash_id, batch_id, priority, queue, params_deterministic_hash, params, domain, test_start_time, undelegated';
my $fields = 'hash_id, batch_id, priority, queue, fingerprint, params, domain, test_start_time, undelegated';
$dbh->do(
"INSERT INTO test_results ($fields) VALUES (?,?,?,?,?,?,?, datetime('now'),?)",
undef,
......@@ -372,12 +372,12 @@ sub add_batch_job {
$dbh->{AutoCommit} = 0;
eval {$dbh->do( "DROP INDEX IF EXISTS test_results__hash_id " );};
eval {$dbh->do( "DROP INDEX IF EXISTS test_results__params_deterministic_hash " );};
eval {$dbh->do( "DROP INDEX IF EXISTS test_results__fingerprint " );};
eval {$dbh->do( "DROP INDEX IF EXISTS test_results__batch_id_progress " );};
eval {$dbh->do( "DROP INDEX IF EXISTS test_results__progress " );};
eval {$dbh->do( "DROP INDEX IF EXISTS test_results__domain_undelegated " );};
my $sth = $dbh->prepare( 'INSERT INTO test_results (hash_id, domain, batch_id, priority, queue, params_deterministic_hash, params, undelegated) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ' );
my $sth = $dbh->prepare( 'INSERT INTO test_results (hash_id, domain, batch_id, priority, queue, fingerprint, params, undelegated) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ' );
foreach my $domain ( @{$params->{domains}} ) {
$test_params->{domain} = $domain;
......@@ -388,7 +388,7 @@ sub add_batch_job {
$sth->execute( substr(md5_hex(time().rand()), 0, 16), $test_params->{domain}, $batch_id, $priority, $queue_label, $fingerprint, $encoded_params, $undelegated );
}
$dbh->do( "CREATE INDEX test_results__hash_id ON test_results (hash_id, creation_time)" );
$dbh->do( "CREATE INDEX test_results__params_deterministic_hash ON test_results (params_deterministic_hash)" );
$dbh->do( "CREATE INDEX test_results__fingerprint ON test_results (fingerprint)" );
$dbh->do( "CREATE INDEX test_results__batch_id_progress ON test_results (batch_id, progress)" );
$dbh->do( "CREATE INDEX test_results__progress ON test_results (progress)" );
$dbh->do( "CREATE INDEX test_results__domain_undelegated ON test_results (domain, undelegated)" );
......
......@@ -16,6 +16,28 @@ my $dbh = $db->dbh;
sub patch_db {
# Rename column "params_deterministic_hash" into "fingerprint"
# Since MariaDB 10.5.2 (2020-03-26) <https://mariadb.com/kb/en/mariadb-1052-release-notes/>
# ALTER TABLE t1 RENAME COLUMN old_col TO new_col;
# Before that we need to use CHANGE COLUMN <https://mariadb.com/kb/en/alter-table/#change-column>
eval {
$dbh->do('ALTER TABLE test_results CHANGE COLUMN params_deterministic_hash fingerprint CHARACTER VARYING(32)');
};
print( "Error while changing DB schema: " . $@ ) if ($@);
# Update index
eval {
# retrieve all indexes by key name
my $indexes = $dbh->selectall_hashref( 'SHOW INDEXES FROM test_results', 'Key_name' );
if ( exists($indexes->{test_results__params_deterministic_hash}) ) {
$dbh->do( "DROP INDEX test_results__params_deterministic_hash ON test_results" );
}
$dbh->do( "CREATE INDEX test_results__fingerprint ON test_results (fingerprint)" );
};
print( "Error while updating the index: " . $@ ) if ($@);
# Update the "undelegated" column
my $sth1 = $dbh->prepare('SELECT id, params from test_results', undef);
$sth1->execute;
while ( my $row = $sth1->fetchrow_hashref ) {
......
......@@ -17,6 +17,28 @@ my $dbh = $db->dbh;
sub patch_db {
# Rename column "params_deterministic_hash" into "fingerprint"
eval {
$dbh->do( 'ALTER TABLE test_results RENAME COLUMN params_deterministic_hash TO fingerprint' );
};
print( "Error while changing DB schema: " . $@ ) if ($@);
# Update index
eval {
# clause IF EXISTS available since PostgreSQL >= 9.2
$dbh->do( "DROP INDEX IF EXISTS test_results__params_deterministic_hash" );
$dbh->do( "CREATE INDEX test_results__fingerprint ON test_results (fingerprint)" );
};
print( "Error while updating the index: " . $@ ) if ($@);
# Add missing "undelegated" column
eval {
$dbh->do( 'ALTER TABLE test_results ADD COLUMN undelegated integer NOT NULL DEFAULT 0' );
};
print( "Error while changing DB schema: " . $@ ) if ($@);
# Update the "undelegated" column
my $sth1 = $dbh->prepare('SELECT id, params from test_results', undef);
$sth1->execute;
while ( my $row = $sth1->fetchrow_hashref ) {
......
......@@ -16,6 +16,22 @@ my $dbh = $db->dbh;
sub patch_db {
# Rename column "params_deterministic_hash" into "fingerprint"
# Since SQLite 3.25 (2018-09-15) <https://sqlite.org/changes.html>
eval {
$dbh->do('ALTER TABLE test_results RENAME COLUMN params_deterministic_hash TO fingerprint');
};
print( "Error while changing DB schema: " . $@ ) if ($@);
# Update index
eval {
$dbh->do( "DROP INDEX IF EXISTS test_results__params_deterministic_hash ON test_results" );
$dbh->do( "CREATE INDEX test_results__fingerprint ON test_results (fingerprint)" );
};
print( "Error while updating the index: " . $@ ) if ($@);
# Update the "undelegated" column
my $sth1 = $dbh->prepare('SELECT id, params from test_results', undef);
$sth1->execute;
while ( my $row = $sth1->fetchrow_hashref ) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment