Skip to content

Commit

Permalink
deps load fix
Browse files Browse the repository at this point in the history
- known error to make created_at and updated_at default to now
  • Loading branch information
sanchitram1 committed Oct 3, 2024
1 parent 2fea97b commit 3d8d448
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/pipeline/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ class DependsOn(Base):
# ideally, these are non-nullable but diff package managers are picky about this
dependency_type = Column(String, nullable=True)
semver_range = Column(String, nullable=True)
# TODO: make these default now now
created_at = Column(DateTime, nullable=False)
updated_at = Column(DateTime, nullable=False)

def to_dict(self):
return {
"version_id": self.version_id,
"dependency_id": self.dependency_id,
"dependency_type": self.dependency_type,
"semver_range": self.semver_range,
# "dependency_type": self.dependency_type,
}


Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/utils/crates/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def dependencies(self):
reader = csv.DictReader(f)
for row in reader:
start_id = row["version_id"]
end_id = row["dependency_id"]
end_id = row["crate_id"]
req = row["req"]
kind = row["kind"]
kind = int(row["kind"])

# map string to enum
dependency_type = DependencyType(kind)
Expand Down
9 changes: 7 additions & 2 deletions src/pipeline/utils/pg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from typing import Iterable, List, Type

from sqlalchemy import UUID, create_engine
from sqlalchemy import UUID, create_engine, func
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.orm import sessionmaker
Expand Down Expand Up @@ -156,14 +156,19 @@ def dependency_object_generator():
continue
dependency_id = dependency.id

now = func.now()

yield DependsOn(
version_id=version_id,
dependency_id=dependency_id,
semver_range=semver_range,
# TODO: db should do this
created_at=now,
updated_at=now,
# dependency_type=dependency_type, TODO: add this
)

self._batch(dependency_object_generator(), DependsOn, 10000)
self._batch(dependency_object_generator(), DependsOn, 100000)

def insert_load_history(self, package_manager_id: str):
with self.session() as session:
Expand Down

0 comments on commit 3d8d448

Please sign in to comment.