|
Packit |
209faa |
// Copyright 2013 The Kyua Authors.
|
|
Packit |
209faa |
// All rights reserved.
|
|
Packit |
209faa |
//
|
|
Packit |
209faa |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
209faa |
// modification, are permitted provided that the following conditions are
|
|
Packit |
209faa |
// met:
|
|
Packit |
209faa |
//
|
|
Packit |
209faa |
// * Redistributions of source code must retain the above copyright
|
|
Packit |
209faa |
// notice, this list of conditions and the following disclaimer.
|
|
Packit |
209faa |
// * Redistributions in binary form must reproduce the above copyright
|
|
Packit |
209faa |
// notice, this list of conditions and the following disclaimer in the
|
|
Packit |
209faa |
// documentation and/or other materials provided with the distribution.
|
|
Packit |
209faa |
// * Neither the name of Google Inc. nor the names of its contributors
|
|
Packit |
209faa |
// may be used to endorse or promote products derived from this software
|
|
Packit |
209faa |
// without specific prior written permission.
|
|
Packit |
209faa |
//
|
|
Packit |
209faa |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
209faa |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
209faa |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
Packit |
209faa |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
Packit |
209faa |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
Packit |
209faa |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
209faa |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit |
209faa |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit |
209faa |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
209faa |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
209faa |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
209faa |
|
|
Packit |
209faa |
#include "cli/cmd_db_migrate.hpp"
|
|
Packit |
209faa |
|
|
Packit |
209faa |
#include <cstdlib>
|
|
Packit |
209faa |
|
|
Packit |
209faa |
#include "cli/common.ipp"
|
|
Packit |
209faa |
#include "store/exceptions.hpp"
|
|
Packit |
209faa |
#include "store/layout.hpp"
|
|
Packit |
209faa |
#include "store/migrate.hpp"
|
|
Packit |
209faa |
#include "utils/cmdline/options.hpp"
|
|
Packit |
209faa |
#include "utils/cmdline/ui.hpp"
|
|
Packit |
209faa |
#include "utils/defs.hpp"
|
|
Packit |
209faa |
#include "utils/format/macros.hpp"
|
|
Packit |
209faa |
#include "utils/fs/path.hpp"
|
|
Packit |
209faa |
|
|
Packit |
209faa |
namespace cmdline = utils::cmdline;
|
|
Packit |
209faa |
namespace config = utils::config;
|
|
Packit |
209faa |
namespace fs = utils::fs;
|
|
Packit |
209faa |
namespace layout = store::layout;
|
|
Packit |
209faa |
|
|
Packit |
209faa |
using cli::cmd_db_migrate;
|
|
Packit |
209faa |
|
|
Packit |
209faa |
|
|
Packit |
209faa |
/// Default constructor for cmd_db_migrate.
|
|
Packit |
209faa |
cmd_db_migrate::cmd_db_migrate(void) : cli_command(
|
|
Packit |
209faa |
"db-migrate", "", 0, 0,
|
|
Packit |
209faa |
"Upgrades the schema of an existing results file to the currently "
|
|
Packit |
209faa |
"implemented version. A backup of the results file is created, but "
|
|
Packit |
209faa |
"this operation is not reversible")
|
|
Packit |
209faa |
{
|
|
Packit |
209faa |
add_option(results_file_open_option);
|
|
Packit |
209faa |
}
|
|
Packit |
209faa |
|
|
Packit |
209faa |
|
|
Packit |
209faa |
/// Entry point for the "db-migrate" subcommand.
|
|
Packit |
209faa |
///
|
|
Packit |
209faa |
/// \param ui Object to interact with the I/O of the program.
|
|
Packit |
209faa |
/// \param cmdline Representation of the command line to the subcommand.
|
|
Packit |
209faa |
/// \param unused_user_config The runtime configuration of the program.
|
|
Packit |
209faa |
///
|
|
Packit |
209faa |
/// \return 0 if everything is OK, 1 if the statement is invalid or if there is
|
|
Packit |
209faa |
/// any other problem.
|
|
Packit |
209faa |
int
|
|
Packit |
209faa |
cmd_db_migrate::run(cmdline::ui* ui, const cmdline::parsed_cmdline& cmdline,
|
|
Packit |
209faa |
const config::tree& UTILS_UNUSED_PARAM(user_config))
|
|
Packit |
209faa |
{
|
|
Packit |
209faa |
try {
|
|
Packit |
209faa |
const fs::path results_file = layout::find_results(
|
|
Packit |
209faa |
results_file_open(cmdline));
|
|
Packit |
209faa |
store::migrate_schema(results_file);
|
|
Packit |
209faa |
return EXIT_SUCCESS;
|
|
Packit |
209faa |
} catch (const store::error& e) {
|
|
Packit |
209faa |
cmdline::print_error(ui, F("Migration failed: %s.") % e.what());
|
|
Packit |
209faa |
return EXIT_FAILURE;
|
|
Packit |
209faa |
}
|
|
Packit |
209faa |
}
|