好吧,我有数据库(Postgres)和Rails作为web框架。
我想知道如何进行表格分区。
好吧,假设我有桌子:Events
并且它有字段created_at
此模型使用act_as_paranoid
gem,这些事件根本没有删除。 (大量的,哦)
我想做下一件事:我想把这个表Events
分区的created_at字段减少到几个月。
好的,我发现了一些关于它的帖子。
Pure postres solution似乎很好。
Presentation讲述了不同的方法
Partitioned gem看起来很简单。
我需要一点开始。
宝石没有为我的任务提供很好的例子
Postgres解决方案与我对数据库管理的知识无关,看起来非常糟糕(我是否需要任何迁移或任何新方案?)。
演示文稿仅包含概述。
假设我开始上课:
class ByCreatedAtField < Partitioned::ByMonthlyTimeField
self.abstract_class = true
belongs_to :event
def self.partition_time_field
return :created_at
end
end
我也有:
class Event < ActiveRecord::Base
# code-cod-e-co-de-c-ode
end
好的,我可以将ActiveRecord::Base
超类替换为我指定的分区。
ByCreatedAtField
。
class Event < ByCreatedAtField
# code-cod-e-co-de-c-ode
end
我被困在这里。
我应该将哪些迁移应用于数据库以使我的表分区?
如何按指定月份检索表Event
?
我需要有关进一步表分区部署的更多解释。
感谢您的时间和帮助!
答案 0 :(得分:0)
请查看宝石的这个例子:https://github.com/fiksu/partitioned/blob/master/examples/start_date.rb
尝试通过created_at更改start_date,您应该得到所需的结果。