我正在构建一个Django ETL引擎,该引擎使用企业API从GitHub中提取数据,以收集有关内部公司协作的指标。我设计了一些模式,我现在意识到由于ORM自动设置的pk(主键),该模式无法扩展。提取的主要特征之一是
id
创建存储库、对日志发表评论等的人。
我最初的想法是让ORM自动设置
身份证件
作为
PK
但这不起作用,因为GET请求将每周运行一次,并且它将引发错误,导致覆盖
ID
主键失败。
我做了一些研究,一个潜在的解决方案是创建一个在这里引用的元类:
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)
有什么方法可以覆盖
身份证件
字段并使
PK
这个
timestamp
字段自每次
GET request
运行该字段是否将填充在应用程序生命周期内不会更改的静态数据?
或者,有没有一种方法可以抛弃多表继承体系结构,转而采用不同的方法呢?
我将从中提取的核心指标如下
top contributor to repository
,
repository with most commits
,
most replied to comments
. 我想能经营一些
filters
在数据上提取这些度量,但我知道这很大程度上依赖于模式设置。
谢谢您!