-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DH-4778 [ai][server] version history refactor (#209)
* DH-4778 [ai][server] version history refactor * [dataherald] Release latest changes Oct 6th --------- Co-authored-by: dishenwang2023 <[email protected]> Co-authored-by: Juan Carlos Jose Camacho <[email protected]>
- Loading branch information
1 parent
6191ce5
commit 6ec3d97
Showing
33 changed files
with
387 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
apps/ai/server/database/migrations/sprint_60/DH-4778_version_history_refactor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pymongo | ||
from bson import ObjectId | ||
|
||
import config | ||
|
||
# run this script after the migration script from engine | ||
if __name__ == "__main__": | ||
query_collection = "queries" | ||
|
||
data_store = pymongo.MongoClient(config.db_settings.mongodb_uri)[ | ||
config.db_settings.mongodb_db_name | ||
] | ||
|
||
try: | ||
data_store["nl_query_response_refs"].rename(query_collection) | ||
except Exception as e: | ||
print(e) | ||
pass | ||
|
||
try: | ||
# rename query_response_id to response_id | ||
data_store[query_collection].update_many( | ||
{}, {"$rename": {"query_response_id": "response_id"}} | ||
) | ||
# rename query_response_id to query_id | ||
data_store["golden_sql_refs"].update_many( | ||
{}, {"$rename": {"query_response_id": "query_id"}} | ||
) | ||
|
||
cursor = data_store[query_collection].find({}) | ||
|
||
for doc in cursor: | ||
query_response = data_store["responses"].find_one( | ||
{"_id": doc["response_id"]} | ||
) | ||
|
||
if query_response: | ||
question_id = ObjectId(query_response["question_id"]) | ||
updated_by = ObjectId(doc["updated_by"]) | ||
|
||
# add new field question id, change updated_by to ObjectId | ||
data_store[query_collection].update_one( | ||
{"_id": doc["_id"]}, | ||
{"$set": {"question_id": question_id, "updated_by": updated_by}}, | ||
) | ||
|
||
golden_sql = data_store["golden_sql_refs"].find_one( | ||
{"query_id": doc["response_id"]} | ||
) | ||
if golden_sql: | ||
# update query_id to be the query id | ||
data_store["golden_sql_refs"].update_one( | ||
{"_id": golden_sql["_id"]}, | ||
{"$set": {"query_id": doc["_id"]}}, | ||
) | ||
|
||
except Exception as e: # noqa: S110 | ||
print(e) | ||
pass |
Submodule dataherald
updated
45 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.