33from decimal import Decimal
44from functools import cached_property
55
6- from shared .reports .types import ReportTotals
76from sqlalchemy import Column , ForeignKey , Table , UniqueConstraint , types
87from sqlalchemy .dialects import postgresql
98from sqlalchemy .dialects .postgresql import UUID
109from sqlalchemy .orm import backref , relationship
1110
1211from database .base import CodecovBaseModel , MixinBaseClass , MixinBaseClassNoExternalID
1312from database .models .core import Commit , CompareCommit , Repository
14- from database .utils import ArchiveField
1513from helpers .clock import get_utc_now
16- from helpers .config import should_write_data_to_storage_config_check
1714from helpers .number import precise_round
1815
1916log = logging .getLogger (__name__ )
@@ -38,13 +35,6 @@ class CommitReport(CodecovBaseModel, MixinBaseClass):
3835 back_populates = "reports_list" ,
3936 cascade = "all, delete" ,
4037 )
41- details = relationship (
42- "ReportDetails" ,
43- back_populates = "report" ,
44- uselist = False ,
45- cascade = "all, delete" ,
46- passive_deletes = True ,
47- )
4838 totals = relationship (
4939 "ReportLevelTotals" ,
5040 back_populates = "report" ,
@@ -129,62 +119,6 @@ class UploadError(CodecovBaseModel, MixinBaseClass):
129119 error_params = Column (postgresql .JSON , default = dict )
130120
131121
132- class ReportDetails (CodecovBaseModel , MixinBaseClass ):
133- __tablename__ = "reports_reportdetails"
134- report_id = Column (types .BigInteger , ForeignKey ("reports_commitreport.id" ))
135- report : CommitReport = relationship (
136- "CommitReport" , foreign_keys = [report_id ], back_populates = "details"
137- )
138- _files_array = Column ("files_array" , postgresql .ARRAY (postgresql .JSONB ))
139- _files_array_storage_path = Column (
140- "files_array_storage_path" , types .Text , nullable = True
141- )
142-
143- def get_repository (self ):
144- return self .report .commit .repository
145-
146- def get_commitid (self ):
147- return self .report .commit .commitid
148-
149- def rehydrate_encoded_data (self , json_files_array ):
150- """This ensures that we always use the files_array with the correct underlying classes.
151- No matter where the data comes from.
152- """
153- return [
154- {
155- ** v ,
156- "file_totals" : ReportTotals (* (v .get ("file_totals" , []))),
157- "diff_totals" : (
158- ReportTotals (* v ["diff_totals" ]) if v ["diff_totals" ] else None
159- ),
160- }
161- for v in json_files_array
162- ]
163-
164- def _should_write_to_storage (self ) -> bool :
165- # Safety check to see if the path to repository is valid
166- # Because we had issues around this before
167- if (
168- self .report is None
169- or self .report .commit is None
170- or self .report .commit .repository is None
171- or self .report .commit .repository .owner is None
172- ):
173- return False
174- is_codecov_repo = self .report .commit .repository .owner .username == "codecov"
175- return should_write_data_to_storage_config_check (
176- "report_details_files_array" ,
177- is_codecov_repo ,
178- self .report .commit .repository .repoid ,
179- )
180-
181- files_array = ArchiveField (
182- should_write_to_storage_fn = _should_write_to_storage ,
183- rehydrate_fn = rehydrate_encoded_data ,
184- default_value_class = list ,
185- )
186-
187-
188122class AbstractTotals (MixinBaseClass ):
189123 branches = Column (types .Integer )
190124 coverage = Column (types .Numeric (precision = 8 , scale = 5 ))
0 commit comments