add social schema, associations

This commit is contained in:
Kyle Drake 2014-04-16 15:16:36 -07:00
parent c0b362ea43
commit cff94803a9
10 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,90 @@
Sequel.migration do
up {
DB.add_column :sites, :title, :text, default: nil
DB.add_column :sites, :twitter_handle, :text, default: nil
DB.add_column :sites, :views, :integer, default: 0
DB.add_column :sites, :stripe_token, :text, default: nil
DB.create_table! :follows do
primary_key :id
Integer :site_id, index: true
Integer :actioning_site_id, index: true
DateTime :created_at, index: true
end
DB.create_table! :tips do
primary_key :id
Integer :site_id, index: true
Integer :actioning_site_id, index: true
DateTime :created_at, index: true
BigDecimal :amount
Integer :stripe_charge_id
end
DB.create_table! :changes do
primary_key :id
Integer :site_id, index: true
DateTime :created_at, index: true
end
DB.create_table! :events do
primary_key :id
Integer :site_id, index: true
Integer :follow_id
Integer :tip_id
Integer :tag_id
Integer :site_update_id
Integer :comment_id
Boolean :notification_seen, default: false
Integer :created_at, index: true
end
DB.create_table! :comments do
primary_key :id
Integer :event_id, index: true
Integer :actioning_site_id
Integer :parent_comment_id
Text :message
DateTime :created_at
DateTime :updated_at
end
DB.create_table! :likes do
primary_key :id
Integer :event_id, index: true
Integer :actioning_site_id
DateTime :created_at
end
DB.create_table! :stats do
primary_key :id
Integer :site_id, index: true
Integer :hits, default: 0
Integer :views, default: 0
DateTime :created_at, index: true
end
DB.create_table! :blocks do
primary_key :id
Integer :site_id, index: true
Integer :actioning_site_id, index: true
DateTime :created_at
end
}
down {
DB.drop_column :sites, :title
DB.drop_column :sites, :twitter_handle
DB.drop_column :sites, :views
DB.drop_column :sites, :stripe_token
DB.drop_table :follows
DB.drop_table :tips
DB.drop_table :changes
DB.drop_table :events
DB.drop_table :comments
DB.drop_table :likes
DB.drop_table :stats
DB.drop_table :blocks
}
end

4
models/block.rb Normal file
View file

@ -0,0 +1,4 @@
class Block < Sequel::Model
many_to_one :site
many_to_one :actioning_site, class: :Block
end

3
models/change.rb Normal file
View file

@ -0,0 +1,3 @@
class Change < Sequel::Model
many_to_one :site
end

3
models/comment.rb Normal file
View file

@ -0,0 +1,3 @@
class Comment < Sequel::Model
many_to_one :event
end

9
models/event.rb Normal file
View file

@ -0,0 +1,9 @@
class Event < Sequel::Model
many_to_one :site
many_to_one :follow
many_to_one :tip
many_to_one :tag
many_to_one :changes
one_to_many :likes
one_to_many :comments
end

4
models/follow.rb Normal file
View file

@ -0,0 +1,4 @@
class Follow < Sequel::Model
many_to_one :site
many_to_one :actioning_site, :class => :Site
end

3
models/like.rb Normal file
View file

@ -0,0 +1,3 @@
class Like < Sequel::Model
many_to_one :event
end

View file

@ -40,8 +40,24 @@ class Site < Sequel::Model
SITE_FILES_ROOT = File.join PUBLIC_ROOT, (ENV['RACK_ENV'] == 'test' ? 'sites_test' : 'sites') SITE_FILES_ROOT = File.join PUBLIC_ROOT, (ENV['RACK_ENV'] == 'test' ? 'sites_test' : 'sites')
many_to_one :server many_to_one :server
many_to_many :tags many_to_many :tags
one_to_many :follows
one_to_many :followings, key: :actioning_site_id, class: :Follow
one_to_many :tips
one_to_many :tippings, key: :actioning_site_id, class: :Tip
one_to_many :blocks
one_to_many :blockings, key: :actioning_site_id, class: :Block
one_to_many :stats
one_to_many :events
one_to_many :changes
class << self class << self
def valid_login?(username, plaintext) def valid_login?(username, plaintext)
site = self[username: username] site = self[username: username]

3
models/stat.rb Normal file
View file

@ -0,0 +1,3 @@
class Stat < Sequel::Model
many_to_one :site
end

4
models/tip.rb Normal file
View file

@ -0,0 +1,4 @@
class Tip < Sequel::Model
many_to_one :site
many_to_one :actioning_site, class: :Site
end