Skip to content

Commit d9a91d9

Browse files
committed
feat(cli): add database storage status command
2 parents 09e1396 + 64ba78b commit d9a91d9

11 files changed

Lines changed: 1320 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
*
3+
* @file DbCommand.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DB_COMMAND_HPP
14+
#define VIX_DB_COMMAND_HPP
15+
16+
#include <string>
17+
#include <vector>
18+
19+
namespace vix::commands
20+
{
21+
/**
22+
* @brief Command entry point for database and storage inspection.
23+
*/
24+
struct DbCommand
25+
{
26+
/**
27+
* @brief Run the db command.
28+
*
29+
* Supported forms:
30+
*
31+
* `vix db`
32+
* `vix db status`
33+
*
34+
* Options:
35+
*
36+
* `--json`
37+
* `--verbose`
38+
*
39+
* @param args Command arguments after `db`.
40+
* @return Process exit code.
41+
*/
42+
static int run(const std::vector<std::string> &args);
43+
44+
/**
45+
* @brief Print db command help.
46+
*
47+
* @return Process exit code.
48+
*/
49+
static int help();
50+
};
51+
}
52+
53+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
*
3+
* @file DbChecker.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DB_CHECKER_HPP
14+
#define VIX_DB_CHECKER_HPP
15+
16+
#include <vix/cli/commands/db/DbTypes.hpp>
17+
18+
namespace vix::commands::db::checker
19+
{
20+
/**
21+
* @brief Inspect the current database storage state.
22+
*
23+
* This function checks the resolved database configuration and inspects
24+
* the filesystem for the SQLite database file, WAL file, SHM file,
25+
* storage directory, storage permissions, and migrations directory.
26+
*
27+
* It does not execute migrations and does not modify the database.
28+
*
29+
* @param cfg Effective database configuration.
30+
* @return Database inspection result.
31+
*/
32+
DbCheckResult check_status(const DbConfig &cfg);
33+
}
34+
35+
#endif
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
*
3+
* @file DbConfig.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DB_CONFIG_HPP
14+
#define VIX_DB_CONFIG_HPP
15+
16+
#include <vix/cli/commands/db/DbTypes.hpp>
17+
18+
#include <optional>
19+
#include <string>
20+
21+
namespace vix::commands::db
22+
{
23+
/**
24+
* @brief Read the current Vix project name.
25+
*
26+
* The project name is resolved from `vix.json` when available.
27+
* If no project name is found, the implementation may fall back to
28+
* the current directory name.
29+
*
30+
* @return The detected project name, or std::nullopt if no name can be resolved.
31+
*/
32+
std::optional<std::string> read_project_name();
33+
34+
/**
35+
* @brief Load database configuration from vix.json.
36+
*
37+
* The configuration is read from the `database` object when available.
38+
*
39+
* Supported keys:
40+
* - `database.engine`
41+
* - `database.sqlite.path`
42+
* - `database.storage`
43+
* - `database.migrations`
44+
*
45+
* Fallbacks:
46+
* - engine defaults to SQLite
47+
* - SQLite path defaults to `storage/<project>.db`
48+
* - storage directory defaults to the database parent directory
49+
* - migrations directory defaults to `migrations`
50+
*
51+
* @return Loaded database configuration.
52+
*/
53+
DbConfig load_db_config();
54+
55+
/**
56+
* @brief Apply command-line database options to the loaded config.
57+
*
58+
* This function currently keeps the configuration unchanged, but it exists
59+
* to keep the db command architecture consistent with other Vix commands.
60+
*
61+
* @param cfg Loaded database configuration.
62+
* @param options Runtime database options.
63+
* @return Effective database configuration.
64+
*/
65+
DbConfig apply_db_options(
66+
DbConfig cfg,
67+
const DbOptions &options);
68+
}
69+
70+
#endif
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
*
3+
* @file DbOutput.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_DB_OUTPUT_HPP
14+
#define VIX_DB_OUTPUT_HPP
15+
16+
#include <vix/cli/commands/db/DbTypes.hpp>
17+
18+
#include <iosfwd>
19+
#include <string>
20+
21+
namespace vix::commands::db::output
22+
{
23+
/**
24+
* @brief Print the database status report.
25+
*
26+
* @param out Output stream.
27+
* @param result Database inspection result.
28+
* @param options Runtime database options.
29+
*/
30+
void print_status(
31+
std::ostream &out,
32+
const DbCheckResult &result,
33+
const DbOptions &options);
34+
35+
/**
36+
* @brief Print the database status report as JSON.
37+
*
38+
* @param out Output stream.
39+
* @param result Database inspection result.
40+
*/
41+
void print_status_json(
42+
std::ostream &out,
43+
const DbCheckResult &result);
44+
45+
/**
46+
* @brief Print the beginning of a database command step.
47+
*
48+
* @param out Output stream.
49+
* @param label Step label.
50+
*/
51+
void step(
52+
std::ostream &out,
53+
const std::string &label);
54+
55+
/**
56+
* @brief Print a successful database message.
57+
*
58+
* @param out Output stream.
59+
* @param message Message to print.
60+
*/
61+
void ok(
62+
std::ostream &out,
63+
const std::string &message);
64+
65+
/**
66+
* @brief Print a database warning message.
67+
*
68+
* @param out Output stream.
69+
* @param message Message to print.
70+
*/
71+
void warn(
72+
std::ostream &out,
73+
const std::string &message);
74+
75+
/**
76+
* @brief Print a database error message.
77+
*
78+
* @param out Output stream.
79+
* @param message Message to print.
80+
*/
81+
void error(
82+
std::ostream &out,
83+
const std::string &message);
84+
85+
/**
86+
* @brief Print a fix suggestion.
87+
*
88+
* @param out Output stream.
89+
* @param message Fix suggestion.
90+
*/
91+
void fix(
92+
std::ostream &out,
93+
const std::string &message);
94+
}
95+
96+
#endif

0 commit comments

Comments
 (0)