Skip to content

Commit 2674241

Browse files
Derb237claude
andcommitted
Add organization name field and additional target fields
- Add name column to Organization model - Update database plugin to handle organization names - Add migration for organization name field - Add target fields: average_payout, start_date, end_date, is_updated - Update upsert logic to include new fields 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c80c175 commit 2674241

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""add organization name
2+
3+
Revision ID: 8b478a84c1a6
4+
Revises: 6f542023f57e
5+
Create Date: 2025-02-11 13:05:40.939271
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '8b478a84c1a6'
14+
down_revision = '6f542023f57e'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
with op.batch_alter_table('organizations') as batch_op:
21+
batch_op.add_column(sa.Column('name', sa.VARCHAR(100)))
22+
23+
24+
def downgrade():
25+
with op.batch_alter_table('organizations') as batch_op:
26+
batch_op.drop_column('name')

src/synack/db/models/organization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
class Organization(Base):
1313
__tablename__ = 'organizations'
1414
slug = sa.Column(sa.VARCHAR(20), primary_key=True)
15+
name = sa.Column(sa.VARCHAR(100))

src/synack/plugins/db.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,24 @@ def add_organizations(self, targets, session=None):
104104
for target in targets:
105105
if isinstance(target.get('organization'), str):
106106
slug = target.get('organization')
107+
name = None # No name available in this case
107108
else:
108-
slug = target.get('organization_id', target.get('organization', {}).get('slug'))
109+
org = target.get('organization', {})
110+
slug = target.get('organization_id', org.get('slug'))
111+
name = org.get('name')
109112
if slug:
110-
organizations_data.append({'slug': slug})
113+
organizations_data.append({
114+
'slug': slug,
115+
'name': name
116+
})
111117

112118
if organizations_data:
113119
stmt = sqlite_insert(Organization).values(organizations_data)
114-
stmt = stmt.on_conflict_do_nothing(
120+
stmt = stmt.on_conflict_do_update(
115121
index_elements=['slug'],
122+
set_={
123+
'name': stmt.excluded.name
124+
}
116125
)
117126
session.execute(stmt)
118127

@@ -200,7 +209,11 @@ def add_targets(self, targets, **kwargs):
200209
'is_active': target.get('isActive', target.get('is_active')),
201210
'is_new': target.get('isNew', target.get('is_new')),
202211
'is_registered': target.get('isRegistered', target.get('is_registered')),
203-
'last_submitted': target.get('lastSubmitted', target.get('last_submitted'))
212+
'last_submitted': target.get('lastSubmitted', target.get('last_submitted')),
213+
'average_payout': target.get('averagePayout'),
214+
'start_date': target.get('start_date'),
215+
'end_date': target.get('end_date'),
216+
'is_updated': target.get('isUpdated', False)
204217
}
205218
target_data.update(kwargs)
206219
targets_data.append(target_data)
@@ -218,6 +231,10 @@ def add_targets(self, targets, **kwargs):
218231
'is_new': stmt.excluded.is_new,
219232
'is_registered': stmt.excluded.is_registered,
220233
'last_submitted': stmt.excluded.last_submitted,
234+
'average_payout': stmt.excluded.average_payout,
235+
'start_date': stmt.excluded.start_date,
236+
'end_date': stmt.excluded.end_date,
237+
'is_updated': stmt.excluded.is_updated
221238
}
222239
)
223240
session.execute(stmt)
@@ -378,7 +395,7 @@ def find_targets(self, **kwargs):
378395
query = query.filter(sa.or_(*filters))
379396
else:
380397
query = query.filter(sa.and_(*filters))
381-
398+
382399
targets = query.all()
383400

384401
session.expunge_all()

0 commit comments

Comments
 (0)