Skip to content

Commit b7271e4

Browse files
committed
fix(orm): update migrator to new driver factory API and fix abstract Connection usage
- Replace removed make_mysql_conn/MySQLConnection with factory-based ConnectionPtr. - Guard DB initialization behind VIX_ORM_HAS_MYSQL / VIX_ORM_HAS_SQLITE. - Fix abstract Connection instantiation error by using ConnectionFactory. - Ensure migrator builds correctly when drivers are disabled in CI.
1 parent b4fec8e commit b7271e4

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

tools/migrator/MigratorCLI.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#include <vix/orm/orm.hpp>
44
#include <vix/orm/FileMigrationsRunner.hpp>
5+
#include <vix/orm/Drivers.hpp>
56

67
#include <iostream>
78
#include <stdexcept>
9+
#include <memory>
810

911
namespace vix::orm::tools
1012
{
@@ -158,30 +160,46 @@ namespace vix::orm::tools
158160
return 0;
159161
}
160162

161-
// Connect (MySQL)
162-
auto raw = vix::orm::make_mysql_conn(opt.host, opt.user, opt.pass, opt.db);
163-
vix::orm::MySQLConnection conn{raw};
163+
// Connect (DB) - Drivers.hpp API
164+
vix::orm::ConnectionPtr conn;
165+
std::unique_ptr<vix::orm::FileMigrationsRunner> runner;
164166

165-
// Run migrations from files
166-
vix::orm::FileMigrationsRunner runner{conn, opt.migrationsDir};
167+
#if VIX_ORM_HAS_MYSQL
168+
{
169+
auto factory = vix::orm::make_mysql_factory(opt.host, opt.user, opt.pass, opt.db);
170+
conn = factory(); // returns std::shared_ptr<Connection>
171+
runner = std::make_unique<vix::orm::FileMigrationsRunner>(*conn, opt.migrationsDir);
172+
}
173+
#elif VIX_ORM_HAS_SQLITE
174+
{
175+
// Si tu ajoutes make_sqlite_factory plus tard
176+
auto factory = vix::orm::make_sqlite_factory(opt.db);
177+
conn = factory();
178+
runner = std::make_unique<vix::orm::FileMigrationsRunner>(*conn, opt.migrationsDir);
179+
}
180+
#else
181+
std::cerr << "[ERR] vix_orm_migrator built without DB drivers.\n"
182+
<< "Enable one with:\n"
183+
<< " -DVIX_ORM_HAS_MYSQL=1 (or add SQLite support)\n";
184+
return 1;
185+
#endif
167186

168187
if (opt.command == "migrate")
169188
{
170-
runner.applyAll();
189+
runner->applyAll();
171190
std::cout << "[OK] migrations applied\n";
172191
return 0;
173192
}
174193

175194
if (opt.command == "rollback")
176195
{
177-
runner.rollback(opt.steps);
196+
runner->rollback(opt.steps);
178197
std::cout << "[OK] rollback " << opt.steps << " step(s)\n";
179198
return 0;
180199
}
181200

182201
if (opt.command == "status")
183202
{
184-
// Minimal status (tant que runner.status() n’existe pas)
185203
std::cout << "[OK] migrations dir: " << opt.migrationsDir << "\n";
186204
std::cout << "Tip: implement FileMigrationsRunner::status() to show applied vs pending.\n";
187205
return 0;
@@ -197,4 +215,5 @@ namespace vix::orm::tools
197215
return 1;
198216
}
199217
}
218+
200219
} // namespace vix::orm::tools

0 commit comments

Comments
 (0)