繁体   English   中英

Rails数据建模:战役建模

[英]Rails Data Modeling: Campaign Modeling

我正在尝试在Rails中构建一个广告网络类型的应用程序,该应用程序将允许创建属性类似于以下内容的广告系列: 在此处输入图片说明

我希望用户能够在一天中选择多个日期,位置和时间段来投放广告系列(如图中所示)。 然后,根据客户的位置,星期几和一天中的时间段,客户将拉出具有相应属性的此类广告。

我知道这是一个复杂的模型,有效地构建它至关重要。 也许有关于如何布局模型的教程或见解?

将日程表存储为iCalendar 规则 (如果您愿意,可以将其存储为更规范的版本)。

创建一个函数以返回该规则的未来日期。

如果需要,可以创建即将到来日期的实例化视图,以提高性能。

PostgreSQL处理RRULE的函数

使用表继承为地理位置建模。 您应该将城市视为州的子级,而不是县的子级,因为某些城市包含县。

您希望能够将单个外键指向抽象的地理位置,例如“俄亥俄州”或“俄亥俄州库霍荷加县”

使用联结表将多个位置映射到活动。

--postgresql syntax

create table campaigns (
  campaign_id int primary key,
  name text unique,
  rrule text not null check ( is_valid_rrule(rrule) ) --you would need to write this
);

create table locations (
  location_id int primary key,
  type text not null check ( type in ('COUNTRY', 'PRIMARY_DIVISION','SECONDARY_DIVISION') ), --use a lookup table in real life
  name text not null,
  parent_id int null references locations (location_id) check ( type = 'COUNTRY' or parent_id is not null),

  unique (name, parent_id)
);

create table campaign_locations (
  campaign_id int references campaigns(campaign_id),
  location_id int references locations(location_id),

  primary key (campaign_id, location_id)
);

--insert some locations:

insert into locations values
(1, 'COUNTRY', 'United States of America', null),
(2, 'PRIMARY_DIVISION', 'Ohio', 1),
(3, 'SECONDARY_DIVISION', 'Cuyahoga County', 2),
(4, 'SECONDARY_DIVISION', 'Adams County', 2);

--create a campaign with a recurrence rule:

insert into campaigns values
(1, 'My Campaign', 'FREQ=WEEKLY;BYDAY=MO,WE');

--associate a campaign with Cuyahoga and Adams counties:

insert into campaign_locations values
(1, 3),
(1, 4);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM