Module: kamailio
Branch: master
Commit: b70ade3e636cec8c38f40c92ec6bab5e7486feee
URL: 
https://github.com/kamailio/kamailio/commit/b70ade3e636cec8c38f40c92ec6bab5e7486feee

Author: Xenofon Karamanos <x...@gilawa.com>
Committer: Xenofon Karamanos <x...@gilawa.com>
Date: 2025-02-03T08:56:59Z

cmake: Generate version-create.mongo file and install it

---

Added: utils/kamctl/generate_version_create_mongo.sh
Modified: utils/kamctl/CMakeLists.txt

---

Diff:  
https://github.com/kamailio/kamailio/commit/b70ade3e636cec8c38f40c92ec6bab5e7486feee.diff
Patch: 
https://github.com/kamailio/kamailio/commit/b70ade3e636cec8c38f40c92ec6bab5e7486feee.patch

---

diff --git a/utils/kamctl/CMakeLists.txt b/utils/kamctl/CMakeLists.txt
index ca8a4f20660..ad7ef141090 100644
--- a/utils/kamctl/CMakeLists.txt
+++ b/utils/kamctl/CMakeLists.txt
@@ -306,11 +306,11 @@ else()
       COMMENT "Cleaning ${db_name} schema files")
   endfunction()
 
-  # Add targets for each database type Pi framework targets should combined 
into
-  # one
+  # Add targets for each database type
   add_custom_target(dbschema COMMENT "Generating schemas for all dbs...")
   add_custom_target(dbschema_clean COMMENT "Cleaning schemas for all dbs...")
 
+  # Pi framework targets should combined into one
   if("xhttp_pi" IN_LIST FINAL_MODULES_LIST)
     add_db_target(pi_framework_table "${STYLESHEETS}/pi_framework_table.xsl")
     add_db_target(pi_framework_mod "${STYLESHEETS}/pi_framework_mod.xsl")
@@ -361,6 +361,24 @@ else()
     add_db_target(mongodb "${STYLESHEETS}/mongodb.xsl")
     add_dependencies(dbschema dbschema_mongodb)
     add_dependencies(dbschema_clean dbschema_mongodb_clean)
+    # Create the version-create.mongo script
+    # After processing the JSON files, create the version-create.mongo script
+    # Usage of generate_version_create_mongo.sh:
+    # 1. The first argument is the path to create the version-create.mongo 
script
+    # 2. The second argument is the path to the directory containing the JSON 
files
+    add_custom_command(
+      TARGET dbschema_mongodb
+      POST_BUILD
+      COMMAND
+        bash ${CMAKE_CURRENT_SOURCE_DIR}/generate_version_create_mongo.sh
+        "${CMAKE_CURRENT_BINARY_DIR}/mongodb/kamailio/version-create.mongo"
+        "${CMAKE_CURRENT_BINARY_DIR}/mongodb/kamailio"
+      COMMENT "Creating version-create.mongo from JSON files")
+
+    install(
+      FILES ${CMAKE_CURRENT_BINARY_DIR}/mongodb/kamailio/version-create.mongo
+      DESTINATION ${CMAKE_INSTALL_DATADIR}/${MAIN_NAME}/mongodb/${MAIN_NAME}
+      COMPONENT KMONGODB)
   endif()
   if("db_redis" IN_LIST FINAL_MODULES_LIST)
     add_db_target(db_redis "${STYLESHEETS}/db_redis.xsl")
diff --git a/utils/kamctl/generate_version_create_mongo.sh 
b/utils/kamctl/generate_version_create_mongo.sh
new file mode 100644
index 00000000000..47048cc0962
--- /dev/null
+++ b/utils/kamctl/generate_version_create_mongo.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+OUTPUT_FILE="$1"
+JSON_DIR="$2"
+
+# Create the version-create.mongo file
+echo "use kamailio;" > "$OUTPUT_FILE"
+echo "db.createCollection(\"version\");" >> "$OUTPUT_FILE"
+
+for FILE in "$JSON_DIR"/*.json; do
+  if [ -f "$FILE" ]; then
+    if [ "$FILE" != "$JSON_DIR/version.json" ]; then
+      VN=$(grep '"version":' "$FILE" | grep -o -E '[0-9]+')
+      FN=$(basename "$FILE" .json)
+      echo "db.getCollection(\"version\").insert({ table_name: \"$FN\", 
table_version: NumberInt($VN) });" >> "$OUTPUT_FILE"
+    fi
+  fi
+done
\ No newline at end of file

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to