Commit 4e7e78ba authored by Francesc Guasch's avatar Francesc Guasch
Browse files

refactor(test): check if trigger already created

parent 6a7276c5
......@@ -1182,10 +1182,21 @@ sub _upgrade_table {
}
warn "INFO: adding $field $definition to $table\n" if $0 !~ /\.t$/;
$dbh->do("alter table $table add $field $definition");
$self->_sqlite_trigger($dbh,$table, $field, $sqlite_trigger) if $sqlite_trigger;
if ( $sqlite_trigger && !$self->_exists_trigger($dbh, "Update$field") ) {
$self->_sqlite_trigger($dbh,$table, $field, $sqlite_trigger);
}
return 1;
}
sub _exists_trigger($self, $dbh, $name) {
my $sth = $dbh->prepare("select name from sqlite_master where type = 'trigger'"
." AND name=?"
);
$sth->execute($name);
my ($found) = $sth->fetchrow;
return $found;
}
sub _sqlite_trigger($self, $dbh, $table,$field, $trigger) {
my $sql =
"CREATE TRIGGER Update$field
......
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