vrfs-927: added new promotional table for home page data

This commit is contained in:
Jonathan Kolyer 2013-12-22 05:22:04 -06:00
parent fcd093f5a6
commit ec126793c7
4 changed files with 76 additions and 0 deletions

View File

@ -81,3 +81,5 @@ notification_band_invite.sql
band_photo_filepicker.sql
bands_geocoding.sql
store_s3_filenames.sql
home_page_promos.sql

View File

@ -0,0 +1,28 @@
--
CREATE TABLE promotionals(
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
/* allows for single table inheritance */
type VARCHAR(128) NOT NULL DEFAULT 'JamRuby::PromoBuzz',
/* state machine */
aasm_state VARCHAR(64) DEFAULT 'hidden',
/* order of promo within its types */
position integer NOT NULL DEFAULT 0,
/* optional expiration date */
expires_at TIMESTAMP DEFAULT NULL,
/* standard AR timestamps */
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
/* references latest recording or session polymorphically */
latest_id VARCHAR(64) DEFAULT NULL,
latest_type VARCHAR(128) DEFAULT NULL,
/* used for buzz promo type */
original_fpfile_photo VARCHAR(8000) DEFAULT NULL,
photo_url VARCHAR(2048) DEFAULT NULL,
text_short VARCHAR(512) DEFAULT NULL,
text_long VARCHAR(4096) DEFAULT NULL
);
CREATE INDEX promo_latest_idx ON promotionals(latest_id, latest_type);

View File

@ -83,6 +83,7 @@ require "jam_ruby/models/mix"
require "jam_ruby/models/claimed_recording"
require "jam_ruby/models/crash_dump"
require "jam_ruby/models/isp_score_batch"
require "jam_ruby/models/promotional"
include Jampb

View File

@ -0,0 +1,45 @@
class JamRuby::Promotional < ActiveRecord::Base
self.table_name = :promotionals
self.abstract_class = true
attr_accessible :expires_at, :position, :aasm_state
include AASM
HIDDEN_STATE = :hidden
ACTIVE_STATE = :active
EXPIRED_STATE = :expired
aasm do
state HIDDEN_STATE, :initial => true
state ACTIVE_STATE
state EXPIRED_STATE
event :activate do
transitions :from => [HIDDEN_STATE, EXPIRED_STATE], :to => ACTIVE_STATE
end
event :expire do
transitions :from => [HIDDEN_STATE, ACTIVE_STATE], :to => EXPIRED_STATE
end
event :hide do
transitions :from => [HIDDEN_STATE, ACTIVE_STATE], :to => HIDDEN_STATE
end
end
def state
aasm_state
end
end
class JamRuby::PromoBuzz < JamRuby::Promotional
attr_accessible :original_fpfile_photo, :photo_url, :text_short, :text_long
end
class JamRuby::PromoLatest < JamRuby::Promotional
belongs_to :latest, :polymorphic => true
end