diff --git a/db/manifest b/db/manifest index 6ddf7a6aa..878961343 100755 --- a/db/manifest +++ b/db/manifest @@ -81,3 +81,5 @@ notification_band_invite.sql band_photo_filepicker.sql bands_geocoding.sql store_s3_filenames.sql +home_page_promos.sql + diff --git a/db/up/home_page_promos.sql b/db/up/home_page_promos.sql new file mode 100644 index 000000000..356fc59c8 --- /dev/null +++ b/db/up/home_page_promos.sql @@ -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); diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index bf158efb0..c09ed211d 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/promotional.rb b/ruby/lib/jam_ruby/models/promotional.rb new file mode 100644 index 000000000..ff87d7548 --- /dev/null +++ b/ruby/lib/jam_ruby/models/promotional.rb @@ -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