-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add db seed restore status check (#2917)
* git push originAdd db seed restore status to health check Add route to expose db seed status * Lint
- Loading branch information
1 parent
210120b
commit fded9cf
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
discovery-provider/src/queries/get_db_seed_restore_status.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,33 @@ | ||
import sqlalchemy | ||
from src.utils.config import shared_config | ||
from src.utils.db_session import get_db_read_replica | ||
|
||
env = shared_config["discprov"]["env"] | ||
|
||
# environment to db file md5 hash lookup, these are constants and will not change | ||
env_to_hash_lookup = {"prod": "c785fc03cfc9cca3e8a48226b9cd424b"} | ||
|
||
|
||
def get_db_seed_restore_status(): | ||
db = get_db_read_replica() | ||
with db.scoped_session() as session: | ||
db_seed_restore_status_query = sqlalchemy.text( | ||
""" | ||
SELECT md5(cast(array_agg(sorted_hashes."str" ORDER BY sorted_hashes."str" ASC) as text)) FROM ( | ||
SELECT (CAST("user_id" AS VARCHAR) || CAST("blocknumber" AS VARCHAR) || "txhash") as "str" | ||
FROM "users" | ||
WHERE "updated_at" BETWEEN '09-01-2021' AND '02-01-2022' | ||
ORDER BY "user_id" ASC, "blocknumber" ASC, "txhash" ASC | ||
) as sorted_hashes; | ||
""" | ||
) | ||
db_hash = session.execute(db_seed_restore_status_query).fetchone()[0] | ||
|
||
env_hash = env_to_hash_lookup.get(env, None) | ||
has_restored = False | ||
seed_hash = db_hash | ||
|
||
if env_hash and env_hash == db_hash: | ||
has_restored = True | ||
|
||
return has_restored, seed_hash |
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