Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first bunch of models for platform #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ pickle-email-*.html

# tilde files are usually backup files from a text editor
*~

# ERD file
erd.pdf
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ group :development, :test do
gem 'byebug'
end
group :development do
gem 'rails-erd'
gem 'web-console', '~> 2.0'
gem 'spring'
end
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ GEM
chartkick (1.4.1)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
choice (0.2.0)
coderay (1.1.0)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -175,6 +176,11 @@ GEM
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-erd (1.4.6)
activerecord (>= 3.2)
activesupport (>= 3.2)
choice (~> 0.2.0)
ruby-graphviz (~> 1.2)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
rails_12factor (0.0.3)
Expand Down Expand Up @@ -219,6 +225,7 @@ GEM
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
ruby-graphviz (1.2.2)
rubyzip (1.1.7)
sass (3.4.21)
sass-rails (5.0.4)
Expand Down Expand Up @@ -314,6 +321,7 @@ DEPENDENCIES
pusher (~> 0.16)
quiet_assets
rails (= 4.2.5.1)
rails-erd
rails_12factor
rails_layout
rspec-rails
Expand Down
3 changes: 0 additions & 3 deletions app/models/measurement.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/models/uc_measurement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class UcMeasurement < ActiveRecord::Base
belongs_to :uc_signal
validates_associated :uc_signal
end
9 changes: 9 additions & 0 deletions app/models/uc_monitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UcMonitor < ActiveRecord::Base
belongs_to :user

has_many :uc_signals_monitors
has_many :uc_signals, through: :uc_signals_monitors

validates :name, :kind, presence: true
validates_associated :uc_signals, :user
end
7 changes: 7 additions & 0 deletions app/models/uc_sensor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class UcSensor < ActiveRecord::Base
has_many :uc_signals
belongs_to :user

validates :name, :kind, presence: true
validates_associated :user
end
13 changes: 13 additions & 0 deletions app/models/uc_signal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class UcSignal < ActiveRecord::Base
belongs_to :uc_sensor
has_many :uc_measurements

has_many :uc_signals_monitors
has_many :uc_monitors, through: :uc_signals_monitors

has_many :uc_conditions_signals
has_many :uc_conditions, through: :uc_conditions_signals

validates :unit, presence: true
validates_associated :uc_sensor
end
5 changes: 5 additions & 0 deletions app/models/uc_signals_monitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class UcSignalsMonitor < ActiveRecord::Base
belongs_to :uc_signal
belongs_to :uc_monitor
end

11 changes: 8 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class User < ActiveRecord::Base
has_many :uc_monitors
has_many :uc_sensors
has_many :uc_actuators
has_many :uc_processes

belongs_to :plan
validates_associated :plan

enum role: [:user, :admin, :silver, :gold, :platinum]
after_initialize :set_default_role, :if => :new_record?
after_initialize :set_default_plan, :if => :new_record?
# after_create :sign_up_for_mailing_list

belongs_to :plan
validates_associated :plan

def set_default_role
self.role ||= :user
end
Expand Down
8 changes: 0 additions & 8 deletions db/migrate/20160231233554_create_measurements.rb

This file was deleted.

13 changes: 13 additions & 0 deletions db/migrate/20160231233554_create_uc_measurements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateUcMeasurements < ActiveRecord::Migration
def change
create_table :uc_measurements do |t|
t.timestamps null: false

t.decimal :value, precision: 12, scale: 3

t.integer :uc_signal_id

t.index :uc_signal_id
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20160309195325_create_uc_sensors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateUcSensors < ActiveRecord::Migration
def change
create_table :uc_sensors do |t|
t.string :name
t.string :description
t.string :kind

t.integer :user_id

t.timestamps null: false
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20160309200556_create_uc_signals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateUcSignals < ActiveRecord::Migration
def change
create_table :uc_signals do |t|
t.timestamps null: false

t.string :unit

t.integer :uc_sensor_id
t.index :uc_sensor_id

end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20160309210843_create_uc_signals_monitors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateUcSignalsMonitors < ActiveRecord::Migration
def change
create_table :uc_signals_monitors do |t|
t.timestamps null: false

t.integer :uc_signal_id
t.integer :uc_monitor_id
end
end
end
14 changes: 14 additions & 0 deletions db/migrate/20160309210907_create_uc_monitors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateUcMonitors < ActiveRecord::Migration
def change
create_table :uc_monitors do |t|
t.timestamps null: false

t.integer :user_id

t.string :name
t.string :kind


end
end
end
174 changes: 76 additions & 98 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,120 +11,98 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160231233554) do
ActiveRecord::Schema.define(version: 20160310131412) do

create_table "measurements", force: :cascade do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "value", precision: 3, scale: 10
create_table "plans", force: :cascade do |t|
t.string "name"
t.string "stripe_id"
t.string "interval"
t.integer "amount"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "payola_affiliates", force: :cascade do |t|
t.string "code"
t.string "email"
t.integer "percent"
t.datetime "created_at"
t.datetime "updated_at"
create_table "uc_actions", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.string "kind"
t.string "value"
t.integer "uc_process_id"
end

create_table "payola_coupons", force: :cascade do |t|
t.string "code"
t.integer "percent_off"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "active", default: true
create_table "uc_actuators", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "name"
t.string "description"
t.string "kind"
end

create_table "payola_sales", force: :cascade do |t|
t.string "email", limit: 191
t.string "guid", limit: 191
t.integer "product_id"
t.string "product_type", limit: 100
t.datetime "created_at"
t.datetime "updated_at"
t.string "state"
t.string "stripe_id"
t.string "stripe_token"
t.string "card_last4"
t.date "card_expiration"
t.string "card_type"
t.text "error"
t.integer "amount"
t.integer "fee_amount"
t.integer "coupon_id"
t.boolean "opt_in"
t.integer "download_count"
t.integer "affiliate_id"
t.text "customer_address"
t.text "business_address"
t.string "stripe_customer_id", limit: 191
t.string "currency"
t.text "signed_custom_fields"
t.integer "owner_id"
t.string "owner_type", limit: 100
create_table "uc_conditions", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.string "logic"
t.integer "uc_process_id"
end

add_index "payola_sales", ["coupon_id"], name: "index_payola_sales_on_coupon_id"
add_index "payola_sales", ["email"], name: "index_payola_sales_on_email"
add_index "payola_sales", ["guid"], name: "index_payola_sales_on_guid"
add_index "payola_sales", ["owner_id", "owner_type"], name: "index_payola_sales_on_owner_id_and_owner_type"
add_index "payola_sales", ["product_id", "product_type"], name: "index_payola_sales_on_product"
add_index "payola_sales", ["stripe_customer_id"], name: "index_payola_sales_on_stripe_customer_id"

create_table "payola_stripe_webhooks", force: :cascade do |t|
t.string "stripe_id"
t.datetime "created_at"
t.datetime "updated_at"
create_table "uc_conditions_signals", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "uc_signal_id"
t.integer "uc_condition_id"
end

create_table "payola_subscriptions", force: :cascade do |t|
t.string "plan_type"
t.integer "plan_id"
t.datetime "start"
t.string "status"
t.string "owner_type"
t.integer "owner_id"
t.string "stripe_customer_id"
t.boolean "cancel_at_period_end"
t.datetime "current_period_start"
t.datetime "current_period_end"
t.datetime "ended_at"
t.datetime "trial_start"
t.datetime "trial_end"
t.datetime "canceled_at"
t.integer "quantity"
t.string "stripe_id"
t.string "stripe_token"
t.string "card_last4"
t.date "card_expiration"
t.string "card_type"
t.text "error"
t.string "state"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "currency"
t.integer "amount"
t.string "guid", limit: 191
t.string "stripe_status"
t.integer "affiliate_id"
t.string "coupon"
t.text "signed_custom_fields"
t.text "customer_address"
t.text "business_address"
t.integer "setup_fee"
t.integer "tax_percent"
create_table "uc_measurements", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.decimal "value", precision: 12, scale: 3
t.integer "uc_signal_id"
end

add_index "payola_subscriptions", ["guid"], name: "index_payola_subscriptions_on_guid"
add_index "uc_measurements", ["uc_signal_id"], name: "index_uc_measurements_on_uc_signal_id"

create_table "plans", force: :cascade do |t|
t.string "name"
t.string "stripe_id"
t.string "interval"
t.integer "amount"
create_table "uc_monitors", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "name"
t.string "kind"
end

create_table "uc_processes", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "name"
t.string "description"
end

create_table "uc_sensors", force: :cascade do |t|
t.string "name"
t.string "description"
t.string "kind"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "uc_signals", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "unit"
t.integer "uc_sensor_id"
end

add_index "uc_signals", ["uc_sensor_id"], name: "index_uc_signals_on_uc_sensor_id"

create_table "uc_signals_monitors", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "uc_signal_id"
t.integer "uc_monitor_id"
end

create_table "users", force: :cascade do |t|
Expand Down
Loading