From f74dba6df74ca1aad58b8406eddfd252cc09d51c Mon Sep 17 00:00:00 2001 From: Jona Date: Mon, 25 Nov 2024 14:45:43 -0500 Subject: [PATCH] NOTE: Add git_hash column to the slick_to_source table --- alembic/versions/3c4693517ef6_add_tables.py | 1 + alembic/versions/7cd715196b8d_add_index.py | 6 ++++++ cerulean_cloud/cloud_function_ais_analysis/main.py | 1 + cerulean_cloud/database_schema.py | 1 + stack/cloud_function_ais_analysis.py | 4 ++++ 5 files changed, 13 insertions(+) diff --git a/alembic/versions/3c4693517ef6_add_tables.py b/alembic/versions/3c4693517ef6_add_tables.py index 39232a95..26f1b2b0 100644 --- a/alembic/versions/3c4693517ef6_add_tables.py +++ b/alembic/versions/3c4693517ef6_add_tables.py @@ -355,6 +355,7 @@ def upgrade() -> None: sa.Column("slick", sa.BigInteger, sa.ForeignKey("slick.id"), nullable=False), sa.Column("source", sa.BigInteger, sa.ForeignKey("source.id"), nullable=False), sa.Column("active", sa.Boolean, nullable=False), + sa.Column("git_hash", sa.Text), sa.Column("coincidence_score", sa.Float), sa.Column("collated_score", sa.Float), sa.Column("rank", sa.BigInteger), diff --git a/alembic/versions/7cd715196b8d_add_index.py b/alembic/versions/7cd715196b8d_add_index.py index b51ac1d1..4c3e9fb8 100644 --- a/alembic/versions/7cd715196b8d_add_index.py +++ b/alembic/versions/7cd715196b8d_add_index.py @@ -41,6 +41,10 @@ def upgrade() -> None: op.create_index("idx_source_name", "source", ["st_name", "type"]) + op.create_index( + "idx_slick_to_source_collated_score", "slick_to_source", ["collated_score"] + ) + op.create_index("idx_slick_to_aoi_slick", "slick_to_aoi", ["slick"]) op.create_index("idx_slick_to_aoi_aoi", "slick_to_aoi", ["aoi"]) @@ -76,6 +80,8 @@ def downgrade() -> None: op.drop_index("idx_source_name", "source") + op.drop_index("idx_slick_to_source_collated_score", "slick_to_source") + op.drop_index("idx_filter_hash", "filter") op.drop_index("idx_slick_hitl", "slick") diff --git a/cerulean_cloud/cloud_function_ais_analysis/main.py b/cerulean_cloud/cloud_function_ais_analysis/main.py index ff7e5c5e..e584d060 100644 --- a/cerulean_cloud/cloud_function_ais_analysis/main.py +++ b/cerulean_cloud/cloud_function_ais_analysis/main.py @@ -152,6 +152,7 @@ async def handle_asa_request(request): source=source.id, slick=slick.id, active=True, + git_hash=os.getenv("GIT_HASH"), coincidence_score=source_row["coincidence_score"], collated_score=source_row["collated_score"], rank=idx + 1, diff --git a/cerulean_cloud/database_schema.py b/cerulean_cloud/database_schema.py index 11de51ba..b00b59bf 100644 --- a/cerulean_cloud/database_schema.py +++ b/cerulean_cloud/database_schema.py @@ -521,6 +521,7 @@ class SlickToSource(Base): # noqa slick = Column(ForeignKey("slick.id"), nullable=False) source = Column(ForeignKey("source.id"), nullable=False) active = Column(Boolean, nullable=False) + git_hash = Column(Text) coincidence_score = Column(Float(53)) collated_score = Column(Float(53)) rank = Column(BigInteger) diff --git a/stack/cloud_function_ais_analysis.py b/stack/cloud_function_ais_analysis.py index 75572926..fc55050f 100644 --- a/stack/cloud_function_ais_analysis.py +++ b/stack/cloud_function_ais_analysis.py @@ -3,6 +3,7 @@ import time import database +import git import pulumi from pulumi_gcp import cloudfunctions, cloudtasks, projects, serviceaccount, storage from utils import construct_name, pulumi_create_zip @@ -35,10 +36,13 @@ ), ) +repo = git.Repo(search_parent_directories=True) +git_sha = repo.head.object.hexsha function_name = construct_name("cf-ais") config_values = { "DB_URL": database.sql_instance_url_with_asyncpg, + "GIT_HASH": git_sha, } # The Cloud Function source code itself needs to be zipped up into an