attaching schema nodes progress
This commit is contained in:
+33
-14
@@ -27,17 +27,31 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
|
||||
dependency_graph[node->name()].push_back(it->second->node().name());
|
||||
|
||||
in_degree[it->second->node().name()] = std::make_pair(0, it->second->node_ptr());
|
||||
in_degree[it->second->node().name()].first++;
|
||||
auto n = it->second->node_ptr();
|
||||
auto nn = node->name();
|
||||
if (it->second->is_has_one()) {
|
||||
continue;
|
||||
}
|
||||
if (const auto dit = in_degree.find(it->second->node().name()); dit == in_degree.end()) {
|
||||
in_degree[it->second->node().name()] = std::make_pair(1, it->second->node_ptr());
|
||||
} else {
|
||||
in_degree[it->second->node().name()].first++;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the current node exists in the graph representation
|
||||
|
||||
if (in_degree.find(node->name()) == in_degree.end()) {
|
||||
in_degree[node->name()].first = 0;
|
||||
in_degree[node->name()] = std::make_pair(0, node);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &it : dependency_graph) {
|
||||
std::cout << "Dependency graph " << it.first << std::endl;
|
||||
for (const auto &neighbor: it.second) {
|
||||
std::cout << " " << neighbor << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
// Step 2: Perform topological sorting (Kahn's Algorithm)
|
||||
std::queue<object::schema::node_ptr> zero_in_degree;
|
||||
std::vector<object::schema::node_ptr> sorted_order;
|
||||
@@ -48,6 +62,11 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &it : in_degree) {
|
||||
std::cout << "In degree table " << it.second.second->name() << " (" << it.second.first << ")" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
while (!zero_in_degree.empty()) {
|
||||
auto current = zero_in_degree.front();
|
||||
zero_in_degree.pop();
|
||||
@@ -65,7 +84,7 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
// Step 3: Check for cycles
|
||||
|
||||
if (sorted_order.size() != in_degree.size()) {
|
||||
throw std::logic_error("Cycle detected in table dependencies");
|
||||
// throw std::logic_error("Cycle detected in table dependencies");
|
||||
}
|
||||
|
||||
// Step 4: Create tables in the sorted order
|
||||
@@ -86,15 +105,15 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
// }
|
||||
}
|
||||
|
||||
auto c = pool_.acquire();
|
||||
for (const auto &node: *schema_) {
|
||||
auto result = query::query::create()
|
||||
.table(node->name(), node->info().definition().columns())
|
||||
.execute(*c);
|
||||
if (!result) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
}
|
||||
// auto c = pool_.acquire();
|
||||
// for (const auto &node: *schema_) {
|
||||
// auto result = query::query::create()
|
||||
// .table(node->name(), node->info().definition().columns())
|
||||
// .execute(*c);
|
||||
// if (!result) {
|
||||
// return utils::failure(result.err());
|
||||
// }
|
||||
// }
|
||||
|
||||
return utils::ok<void>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user