最佳数据库架构重点是同时按年份和月份存储不同字段的数据。

huangapple go评论64阅读模式
英文:

Best approach for database architecture heavily focused on storing data of different fields by year and by months at the same time

问题

我需要把这个方法掌握好,因为我认为如果项目变得足够大,数据库的架构可能会变得陈旧。

我的问题是,根据我设计的当前架构,数据库会呈指数增长,如下所示:

entity Project {
    projectId Long required
}

entity ProjectData {
    yearId Long required
}

entity ProjectMetaData {
    projectManager String,
    company String,
    agency String
}

entity FinancialData {
    monthId Long required
}

entity KpiInfo {
    otd Long,
    oqd Long,
    cumulatedOqd Long,
    cumulatedOtd Long
}

entity ProductionInfo {
    averageDailyCost Long,
    averageDailyRevenue Long,
    managementWorkload Long,
    internalWorkload Long,
    offshoreWorkload Long
}

relationship OneToOne {
    Project to ProjectMetaData
    ProjectData to FinancialData
}

relationship OneToMany {
    Project to ProjectData
    FinancialData to KpiInfo
    FinancialData to ProductionInfo
}

图表如下:
diagram

基本上,Project 有唯一的项目ID,每个项目都有其 ProjectMetaDataProjectData,之后对于项目运行的每一年,都有 FinancialData,并且对于该年的每个月,都有 KpiInfoProductionInfo。因此,如果我从过去的4年获取数据直到现在,这意味着我为单个项目创建了约120个以上的表格,这是我担心的地方,如果应用程序变得足够大,如我之前提到的,这将意味着以后不太容易扩展。

对于这种具有相同字段的多个版本的数据库,是否有常见的方法?

预先感谢您的回答,如果我没有表述清楚,我会很乐意回答关于我的问题的任何疑问。

英文:

I need to nail this approach as I think the architecture of the database could age badly if the project becomes big enough.

My problem is that with the current architecture that I have designed, the database would grow exponentially as it lays like this:

entity Project {
    projectId Long required
}

entity ProjectData {
    yearId Long required
}

entity ProjectMetaData {
    projectManager String,
    company String,
    agency String
}

entity FinancialData {
    monthId Long required
}

entity KpiInfo {
    otd Long,
    oqd Long,
    cumulatedOqd Long,
    cumulatedOtd Long
}

entity ProductionInfo {
    averageDailyCost Long,
    averageDailyRevenue Long,
    managementWorkload Long,
    internalWorkload Long,
    offshoreWorkload Long
}

relationship OneToOne {
    Project to ProjectMetaData
    ProjectData to FinancialData
}

relationship OneToMany {
    Project to ProjectData
    FinancialData to KpiInfo
    FinancialData to ProductionInfo
}

The diagram looks like this:
diagram

Basically a Project has a unique project ID and each Project has its ProjectMetaData and its ProjectData, after that for each year that the project has been going on the project has FinancialData, and for each month of that year, there is KpiInfo and ProductionInfo. Therefore if I am getting data from the past 4 years until now it means I am creating around 120+ tables for a single project and this is where I'm concerned, if the app. becomes big enough as I mentioned before this will mean it will not be very scalable afterwards.

Is there any common approach for this kind of data-bases where there are many versions of the same fields?

Thanks in advance and sorry if I haven't made myself very clear, I will be glad to respond to any doubts regarding my question

答案1

得分: 1

我曾经在一个团队中,他们需要为一个企业建立一个奇怪的公司日历的数据库。他们有一个财政年度,分为财政季度,再分为财政月份,再分为财政周。他们希望能够根据这些日期分组生成历史报告。

最终,我们创建了一个名为"Almanac"的表,每天一行,主键是以某种合适的格式表示的日期。表中有列用于财政年度、财政月份等信息。然后,我们创建了一个生成器程序,用约十年的数据填充了这个表,应用了公司的所有财政日期分组规则。

当我们需要基于这些分组生成历史摘要时,我们只需在日期上将交易数据与"Almanac"表进行连接,然后使用"Almanac"表的列进行分组。

你可能可以将这个概念适应到你的情况中。数据库会增长,但连接可能在未来一段时间内是合理的。

英文:

I once was on a team that had to build a database for an enterprise that had a strange company calendar. They had a fiscal year, divided into fiscal quarters, divided into fiscal months, divided into fiscal weeks. They wanted historical reports grouped by any one of these date groupings.
what we ended up doing was creating a table called Almanac that had one row per day, and the primary key was the date in some suitable format. The table had columns for Fiscal year, fiscal month, etc.
We then created a generator program that populated this table with about ten years worth of data, applying all of the company's rules for fiscal date groupings.
When we needed to produce historical summaries based on these groupings, we simply joined the transaction data to the Almanac table on date, and then used the Almanac columns for Group By purposes.

You might be able to adapt this concept to your case. The database will grow, but the join may be reasonable for some time to come.

答案2

得分: 1

以下是翻译好的部分:

"Add the year and month as columns in the table. Better yet, add a date column. You could set the day as the 1st or the maximum for that month."

将年份和月份添加为表格的列。最好还添加一个日期列。您可以将日期设置为该月的第一天或最后一天。

"entity KpiInfo {
year
month
otd Long,
oqd Long,
cumulatedOqd Long,
cumulatedOtd Long
}"

实体 KpiInfo {
年份
月份
otd 长整型,
oqd 长整型,
累计Oqd 长整型,
累计Otd 长整型
}

"This one table will now suffice for all time into the future. Yes, you will insert 12 rows every year."

这个表格现在将足够用于未来的所有时间。是的,您每年将插入12行。

英文:

It's hard to tell with the limited information you're providing, but I'm going to use one table as an example.

Add the year and month as columns in the table. Better yet, add a date column. You could set the day as the 1st or the maximum for that month.

entity KpiInfo {
    year
    month
    otd Long,
    oqd Long,
    cumulatedOqd Long,
    cumulatedOtd Long
}

This one table will now suffice for all time into the future. Yes, you will insert 12 rows every year.

huangapple
  • 本文由 发表于 2020年8月6日 16:30:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63279716.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定