【发布时间】:2019-10-05 07:11:55
【问题描述】:
我正在构建一个 Django ETL 引擎,该引擎使用企业 API 从 GitHub 提取数据,以收集有关公司内部协作的指标。我设计了一些架构,我现在意识到由于 ORM 自动设置的 PK(主键)而无法扩展。提取的主要功能之一是获取创建存储库、评论帖子等的人的id。
我最初的想法是让 ORM 自动将 id 设置为 PK 但这不起作用,因为 GET 请求将每周运行一次,它会引发错误,导致覆盖 @ 987654325@主键失效。
我做了一些研究,一个潜在的解决方案是创建一个元类,如下所示:Django model primary key as a pair
但我不确定创建几个元类是否会破坏元类的全部意义。
这是我为 models.py 设置的架构
from django.db import models
from datetime import datetime
""" Contruction of tables in MySQL instance """
class Repository(models.Model):
id = models.PositiveIntegerField(null=False, primary_key=True)
repo_name = models.CharField(max_length=50)
creation_date = models.CharField(max_length=21, null=True)
last_updated = models.CharField(max_length=30, null=True)
qty_watchers = models.PositiveIntegerField(null=True)
qty_forks = models.PositiveIntegerField(null=True)
qty_issues = models.PositiveIntegerField(null=True)
main_language = models.CharField(max_length=30, null=True)
repo_size = models.PositiveIntegerField(null=True)
timestamp = models.DateTimeField(auto_now=True)
class Contributor(models.Model):
id = models.IntegerField(null=False, primary_key=True)
contributor_cec = models.CharField(max_length=30, null=True)
contribution_qty = models.PositiveIntegerField(null=True)
get_request = models.CharField(max_length=100, null=True)
timestamp = models.DateTimeField(auto_now=True)
class Teams(models.Model):
id = models.IntegerField(primary_key=True, null=False)
team_name = models.CharField(max_length=100, null=True)
timestamp = models.DateTimeField(auto_now=True)
class TeamMembers(models.Model):
id = models.IntegerField(null=False, primary_key=True)
team_member_cec = models.CharField(max_length=30, null=True)
get_request = models.CharField(max_length=100, null=True)
timestamp = models.DateTimeField(auto_now=True)
class Discussions(models.Model):
id = models.IntegerField(null=False, primary_key=True)
login = models.CharField(max_length=30, null=True)
title = models.CharField(max_length=30, null=True)
body = models.CharField(max_length=1000, null=True)
comments = models.IntegerField(null=True)
updated_at = models.CharField(max_length=21, null=True)
get_request = models.CharField(max_length=100, null=True)
timestamp = models.DateTimeField(auto_now=True)
有没有办法覆盖 id 字段并使 PK 成为 timestamp 字段,因为每次运行 GET request 时,该字段将填充静态数据,这些数据在应用程序?
或者,有没有办法放弃多表继承架构并采用不同的方式?
我将从中提取的核心指标是top contributor to repository、repository with most commits、most replied to comments。我希望能够在数据上运行某种 filters 以便提取这些指标,但我知道这在很大程度上依赖于架构设置。
谢谢!
【问题讨论】: