Skip to content

Commit bd32e80

Browse files
committed
fix(cli): integrate db module and clean warnings
1 parent d55b155 commit bd32e80

6 files changed

Lines changed: 40 additions & 69 deletions

File tree

CMakeLists.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ else()
151151
set(_VIX_P2P_DIR "${_VIX_MODULES_DIR}/p2p")
152152
set(_VIX_SYNC_DIR "${_VIX_MODULES_DIR}/sync")
153153
set(_VIX_CACHE_DIR "${_VIX_MODULES_DIR}/cache")
154-
set(_VIX_AGENT_DIR "${_VIX_MODULES_DIR}/agent")
154+
set(_VIX_AGENT_DIR "${_VIX_MODULES_DIR}/agent")
155+
set(_VIX_DB_DIR "${_VIX_MODULES_DIR}/db")
155156
set(_VIX_WEBSOCKET_DIR "${_VIX_MODULES_DIR}/websocket")
156157

157158
set(_LOCAL_LAYOUT_OK FALSE)
@@ -206,6 +207,12 @@ else()
206207
add_subdirectory("${_VIX_AGENT_DIR}" "${CMAKE_BINARY_DIR}/_vix_ai_agent")
207208
endif()
208209

210+
if (EXISTS "${_VIX_DB_DIR}/CMakeLists.txt" AND NOT TARGET vix::db)
211+
set(VIX_DB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
212+
set(VIX_DB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
213+
add_subdirectory("${_VIX_DB_DIR}" "${CMAKE_BINARY_DIR}/_vix_db")
214+
endif()
215+
209216
if (EXISTS "${_VIX_WEBSOCKET_DIR}/CMakeLists.txt" AND NOT TARGET vix::websocket)
210217
set(VIX_WEBSOCKET_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
211218
add_subdirectory("${_VIX_WEBSOCKET_DIR}" "${CMAKE_BINARY_DIR}/_vix_websocket")
@@ -259,6 +266,10 @@ else()
259266
list(APPEND _VIX_LOCAL_LINK_TARGETS vix::ai_agent)
260267
endif()
261268

269+
if (TARGET vix::db)
270+
list(APPEND _VIX_LOCAL_LINK_TARGETS vix::db)
271+
endif()
272+
262273
if (TARGET vix::websocket)
263274
list(APPEND _VIX_LOCAL_LINK_TARGETS vix::websocket)
264275
endif()
@@ -279,6 +290,7 @@ else()
279290
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_SYNC_DIR}/include")
280291
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_CACHE_DIR}/include")
281292
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_AGENT_DIR}/include")
293+
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_DB_DIR}/include")
282294
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_WEBSOCKET_DIR}/include")
283295
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_P2P_DIR}/include")
284296

@@ -341,6 +353,17 @@ else()
341353
message(STATUS "[cli] Game command disabled: vix::game target not found")
342354
endif()
343355

356+
# ----------------------------------------------------
357+
# Optional db command support
358+
# ----------------------------------------------------
359+
if (TARGET vix::db)
360+
message(STATUS "[cli] DB command enabled")
361+
target_link_libraries(vix_cli PRIVATE vix::db)
362+
target_compile_definitions(vix_cli PRIVATE VIX_CLI_HAS_DB=1)
363+
else()
364+
message(STATUS "[cli] DB command disabled: vix::db target not found")
365+
endif()
366+
344367
# ----------------------------------------------------
345368
# Optional websocket command support
346369
# ----------------------------------------------------

src/build/BuildStyle.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,6 @@ namespace vix::cli::build
103103
<< "\n";
104104
}
105105

106-
static void print_optional_line(
107-
std::ostream &out,
108-
const std::string &label,
109-
const std::string &value)
110-
{
111-
if (value.empty())
112-
return;
113-
114-
print_label(out, label);
115-
out << " " << value << "\n\n";
116-
}
117-
118106
static void print_compact_optional_line(
119107
std::ostream &out,
120108
const std::string &label,

src/commands/AgentCommand.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,6 @@ namespace vix::commands::AgentCommand
138138
return std::to_string(timeout_ms) + "ms";
139139
}
140140

141-
[[nodiscard]] std::string format_duration_ms(long long milliseconds)
142-
{
143-
std::ostringstream oss;
144-
145-
const double seconds =
146-
static_cast<double>(milliseconds) / 1000.0;
147-
148-
oss.setf(std::ios::fixed);
149-
oss.precision(seconds >= 10.0 ? 1 : 2);
150-
oss << seconds << "s";
151-
152-
return oss.str();
153-
}
154-
155141
[[nodiscard]] bool parse_options(
156142
const std::vector<std::string> &args,
157143
Options &options)

src/commands/BuildCommand.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,25 +2035,6 @@ namespace vix::commands::BuildCommand
20352035
return false;
20362036
}
20372037

2038-
static bool node_metadata_changed(
2039-
const build::BuildNode &current,
2040-
const build::BuildNode &previous)
2041-
{
2042-
if (current.hash != previous.hash)
2043-
return true;
2044-
2045-
if (current.size != previous.size)
2046-
return true;
2047-
2048-
if (current.mtime != previous.mtime)
2049-
return true;
2050-
2051-
if (current.state != previous.state)
2052-
return true;
2053-
2054-
return false;
2055-
}
2056-
20572038
static std::string explain_node_change(
20582039
const build::BuildNode &current,
20592040
const build::BuildNode *previous)

src/commands/InstallCommand.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ namespace vix::commands
220220
return store_git_dir() / sanitize_id_dot(id) / commit;
221221
}
222222

223-
static fs::path global_pkg_dir(const std::string &id, const std::string &commit)
224-
{
225-
return global_pkgs_dir() / sanitize_id_dot(id) / commit;
226-
}
227-
228223
static fs::path entry_path(const std::string &ns, const std::string &name)
229224
{
230225
return registry_index_dir() / (ns + "." + name + ".json");

src/commands/db/DbMigrator.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
#include <vix/cli/commands/db/DbMigrator.hpp>
1414
#include <vix/cli/commands/db/DbOutput.hpp>
1515
#include <vix/cli/util/Ui.hpp>
16+
17+
#ifdef VIX_CLI_HAS_DB
1618
#include <vix/db/Database.hpp>
1719
#include <vix/db/mig/FileMigrationsRunner.hpp>
20+
#endif
1821

1922
#include <exception>
2023
#include <filesystem>
@@ -27,23 +30,11 @@ namespace vix::commands::db::migrator
2730
{
2831
namespace
2932
{
30-
/**
31-
* @brief Check whether the selected database engine is SQLite.
32-
*
33-
* @param cfg Database configuration.
34-
* @return true if SQLite is selected.
35-
*/
3633
bool is_sqlite(const DbConfig &cfg)
3734
{
3835
return cfg.engine == DbEngine::SQLite;
3936
}
4037

41-
/**
42-
* @brief Validate filesystem preconditions before running migrations.
43-
*
44-
* @param cfg Database configuration.
45-
* @return true if migration can continue.
46-
*/
4738
bool validate_migration_inputs(const DbConfig &cfg)
4839
{
4940
if (!is_sqlite(cfg))
@@ -54,7 +45,7 @@ namespace vix::commands::db::migrator
5445

5546
output::fix(
5647
std::cerr,
57-
"set database.engine to sqlite or use the ORM command for other engines");
48+
"set database.engine to sqlite");
5849

5950
return false;
6051
}
@@ -90,11 +81,6 @@ namespace vix::commands::db::migrator
9081
return true;
9182
}
9283

93-
/**
94-
* @brief Print the migration summary.
95-
*
96-
* @param cfg Database configuration.
97-
*/
9884
void print_migration_summary(const DbConfig &cfg)
9985
{
10086
output::step(std::cout, "Database Migrations");
@@ -111,6 +97,17 @@ namespace vix::commands::db::migrator
11197
{
11298
(void)options;
11399

100+
#ifndef VIX_CLI_HAS_DB
101+
output::error(
102+
std::cerr,
103+
"vix db migrate is not available in this build.");
104+
105+
output::fix(
106+
std::cerr,
107+
"rebuild the Vix CLI with the db module enabled");
108+
109+
return 1;
110+
#else
114111
if (!validate_migration_inputs(cfg))
115112
return 1;
116113

@@ -143,5 +140,6 @@ namespace vix::commands::db::migrator
143140

144141
return 1;
145142
}
143+
#endif
146144
}
147145
}

0 commit comments

Comments
 (0)