Commit b9c29a90 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Merge branch 'develop' of https://github.com/UPC/ravada into develop

parents 4525c37b b28c9ed6
......@@ -138,6 +138,7 @@ sub BUILD {
sub _install($self) {
$self->_create_tables();
$self->_upgrade_tables();
$self->_upgrade_timestamps();
$self->_update_data();
$self->_init_user_daemon();
}
......@@ -1274,6 +1275,30 @@ sub _upgrade_tables {
$self->_upgrade_table('domain_ports', 'internal_ip','char(200)');
}
sub _upgrade_timestamps($self) {
return if $CONNECTOR->dbh->{Driver}{Name} !~ /mysql/;
my $req = Ravada::Request->ping_backend();
return if $req->{date_changed};
my @commands = qw(cleanup enforce_limits list_isos list_network_interfaces
manage_pools open_exposed_ports open_iptables ping_backend
refresh_machine refresh_storage refresh_vms
screenshot);
my $sql ="DELETE FROM requests WHERE "
.join(" OR ", map { "command = '$_'" } @commands);
my $sth = $CONNECTOR->dbh->prepare($sql);
$sth->execute();
$self->_upgrade_timestamp('requests','date_changed');
}
sub _upgrade_timestamp($self, $table, $field) {
my $sth = $CONNECTOR->dbh->prepare("ALTER TABLE $table change $field "
."$field timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP");
$sth->execute();
}
sub _connect_dbh {
my $driver= ($CONFIG->{db}->{driver} or 'mysql');;
......
......@@ -3,7 +3,7 @@ CREATE TABLE `requests` (
`command` char(32) DEFAULT NULL,
`args` char(255) DEFAULT NULL,
`date_req` datetime DEFAULT NULL,
`date_changed` timestamp ,
`date_changed` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
`status` char(64) DEFAULT NULL,
`error` text DEFAULT NULL,
`id_domain` int(11) DEFAULT NULL,
......
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