Skip to content

Commit

Permalink
DH5669/adding the script to update dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadrezaPourreza committed Apr 2, 2024
1 parent 941493a commit e2a6fc3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions dataherald/scripts/populate_dialect_db_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import dataherald.config
from dataherald.config import System
from dataherald.db import DB
from dataherald.sql_database.models.types import DatabaseConnection
from dataherald.utils.encrypt import FernetEncrypt

if __name__ == "__main__":
settings = dataherald.config.Settings()
system = System(settings)
system.start()
storage = system.instance(DB)
fernet_encrypt = FernetEncrypt()
database_connections = storage.find_all("database_connections")
for database_connection in database_connections:
if not database_connection.get("dialect"):
decrypted_uri = fernet_encrypt.decrypt(database_connection["connection_uri"])
dialect_prefix = DatabaseConnection.validate_uri(decrypted_uri)
dialect = DatabaseConnection.set_dialect(dialect_prefix)
storage.update_or_create(
"database_connections",
{"_id": database_connection["_id"]},
{"dialect": dialect},
)

0 comments on commit e2a6fc3

Please sign in to comment.