Skip to content

Commit

Permalink
Add server_default value to avoid null tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-codecov committed Sep 3, 2024
1 parent 9078de2 commit deac944
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions database/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from google.cloud import pubsub_v1
from shared.config import get_config
from sqlalchemy import event
from sqlalchemy import event, inspect

from database.models.core import Repository

Expand Down Expand Up @@ -51,5 +51,10 @@ def after_insert_repo(mapper, connection, target):

@event.listens_for(Repository, "after_update")
def after_update_repo(mapper, connection, target):
log.info("After update signal")
_sync_repo(target)
state = inspect(target)

for attr in state.attrs:
if attr.key in ["name", "upload_token"] and attr.history.has_changes():
log.info("After update signal")
_sync_repo(target)
break
1 change: 1 addition & 0 deletions database/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Repository(CodecovBaseModel):
webhook_secret = Column(types.Text)
activated = Column(types.Boolean, default=False)
bundle_analysis_enabled = Column(types.Boolean, default=False)
upload_token = Column(postgresql.UUID, server_default=FetchedValue())

# DEPRECATED - prefer GithubAppInstallation.is_repo_covered_by_integration
using_integration = Column(types.Boolean)
Expand Down
5 changes: 5 additions & 0 deletions database/tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def test_shelter_repo_sync(dbsession, mock_configuration, mocker):
repo.name = "testing"
dbsession.commit()

# this wouldn't trigger the publish via SQLAlchemy events (after_update) since it's an unimportant attribute
repo.activated = True
dbsession.commit()

# this is from the first trigger
publish.assert_called_once_with(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "repo", "sync": "one", "id": 91728376}',
Expand Down

0 comments on commit deac944

Please sign in to comment.