Add `scenic` gem for view management
parent
2040feece1
commit
2d2d80d5cf
1
Gemfile
1
Gemfile
|
@ -28,6 +28,7 @@ gem "secure_headers"
|
|||
gem "valid_url"
|
||||
gem "font-awesome-rails"
|
||||
gem "discard", "~> 1.0"
|
||||
gem "scenic"
|
||||
|
||||
group :development, :test do
|
||||
gem "hashdiff"
|
||||
|
|
|
@ -282,6 +282,9 @@ GEM
|
|||
rspec-support (3.7.1)
|
||||
ruby-graphviz (1.2.3)
|
||||
rubyzip (1.2.1)
|
||||
scenic (1.4.1)
|
||||
activerecord (>= 4.0.0)
|
||||
railties (>= 4.0.0)
|
||||
secure_headers (5.0.5)
|
||||
useragent (>= 0.15.0)
|
||||
selenium-webdriver (3.11.0)
|
||||
|
@ -369,6 +372,7 @@ DEPENDENCIES
|
|||
rollbar
|
||||
rspec
|
||||
rspec-rails
|
||||
scenic
|
||||
secure_headers
|
||||
selenium-webdriver
|
||||
simplecov
|
||||
|
|
|
@ -59,6 +59,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def broadcast!
|
||||
# `espeak "ding"`
|
||||
AutoSyncJob.perform_later(broadcast_payload,
|
||||
Device.current.id,
|
||||
chan_name,
|
||||
|
|
|
@ -1,35 +1,7 @@
|
|||
class CreateSequenceToolsView < ActiveRecord::Migration[5.1]
|
||||
def up
|
||||
execute 'CREATE VIEW in_use_tools AS
|
||||
SELECT
|
||||
tools.id as tool_id,
|
||||
tools.name as tool_name,
|
||||
sequences.name as sequence_name,
|
||||
sequences.id as sequence_id,
|
||||
sequences.device_id as device_id
|
||||
FROM "edge_nodes"
|
||||
INNER JOIN "sequences" ON sequences.id=sequences.id
|
||||
INNER JOIN "tools" ON (edge_nodes.value)::int=tools.id
|
||||
WHERE "edge_nodes"."kind" = \'tool_id\';'
|
||||
|
||||
execute 'CREATE VIEW in_use_points AS
|
||||
SELECT
|
||||
points.x as x,
|
||||
points.y as y,
|
||||
points.z as z,
|
||||
(edge_nodes.value)::int as point_id,
|
||||
points.pointer_type as pointer_type,
|
||||
points.name as pointer_name,
|
||||
sequences.id as sequence_id,
|
||||
sequences.name as sequence_name,
|
||||
edge_nodes.id as edge_node_id
|
||||
FROM "edge_nodes"
|
||||
INNER JOIN "sequences" ON edge_nodes.sequence_id=sequences.id
|
||||
INNER JOIN "points" ON (edge_nodes.value)::int=points.id
|
||||
WHERE "edge_nodes"."kind" = \'pointer_id\';'
|
||||
end
|
||||
|
||||
def down
|
||||
def change
|
||||
# I goofed up on this migration and deployed to staging before I could fix.
|
||||
# See later migration that creates a new view using the `scenic` gem.
|
||||
execute "DROP VIEW IF EXISTS in_use_tools;"
|
||||
execute "DROP VIEW IF EXISTS in_use_points;"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
class CreateInUseResources < ActiveRecord::Migration[5.1]
|
||||
# I goofed up on this migration and deployed to staging before I could fix.
|
||||
# See later migration that creates a new view using the `scenic` gem. - RC
|
||||
def up
|
||||
execute "DROP VIEW IF EXISTS in_use_tools;"
|
||||
execute "DROP VIEW IF EXISTS in_use_points;"
|
||||
|
||||
create_view :in_use_tools
|
||||
create_view :in_use_points
|
||||
end
|
||||
|
||||
def down
|
||||
drop_view :in_use_tools
|
||||
drop_view :in_use_points
|
||||
end
|
||||
end
|
31
db/schema.rb
31
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20180410180929) do
|
||||
ActiveRecord::Schema.define(version: 20180410192539) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -483,4 +483,33 @@ ActiveRecord::Schema.define(version: 20180410180929) do
|
|||
add_foreign_key "sensor_readings", "devices"
|
||||
add_foreign_key "sensors", "devices"
|
||||
add_foreign_key "token_issuances", "devices"
|
||||
|
||||
create_view "in_use_tools", sql_definition: <<-SQL
|
||||
SELECT tools.id AS tool_id,
|
||||
tools.name AS tool_name,
|
||||
sequences.name AS sequence_name,
|
||||
sequences.id AS sequence_id,
|
||||
sequences.device_id
|
||||
FROM ((edge_nodes
|
||||
JOIN sequences ON ((sequences.id = sequences.id)))
|
||||
JOIN tools ON (((edge_nodes.value)::integer = tools.id)))
|
||||
WHERE ((edge_nodes.kind)::text = 'tool_id'::text);
|
||||
SQL
|
||||
|
||||
create_view "in_use_points", sql_definition: <<-SQL
|
||||
SELECT points.x,
|
||||
points.y,
|
||||
points.z,
|
||||
(edge_nodes.value)::integer AS point_id,
|
||||
points.pointer_type,
|
||||
points.name AS pointer_name,
|
||||
sequences.id AS sequence_id,
|
||||
sequences.name AS sequence_name,
|
||||
edge_nodes.id AS edge_node_id
|
||||
FROM ((edge_nodes
|
||||
JOIN sequences ON ((edge_nodes.sequence_id = sequences.id)))
|
||||
JOIN points ON (((edge_nodes.value)::integer = points.id)))
|
||||
WHERE ((edge_nodes.kind)::text = 'pointer_id'::text);
|
||||
SQL
|
||||
|
||||
end
|
||||
|
|
17
db/seeds.rb
17
db/seeds.rb
|
@ -9,8 +9,8 @@ unless Rails.env == "production"
|
|||
LogDispatch.destroy_all
|
||||
|
||||
User.destroy_all
|
||||
POINT_COUNT = 2
|
||||
PLANT_COUNT = 2
|
||||
POINT_COUNT = 8
|
||||
PLANT_COUNT = 8
|
||||
DATE_RANGE_LO = 1..3
|
||||
DATE_RANGE_HI = 3..8
|
||||
ENV['MQTT_HOST'] = "blooper.io"
|
||||
|
@ -51,25 +51,22 @@ unless Rails.env == "production"
|
|||
end
|
||||
|
||||
PLANT_COUNT.times do
|
||||
Point.create(
|
||||
device: u.device,
|
||||
Plant.create(device: u.device,
|
||||
x: rand(40...970),
|
||||
y: rand(40...470),
|
||||
radius: rand(10...50),
|
||||
name: Faker::StarWars.call_sign,
|
||||
pointer: Plant.new(
|
||||
openfarm_slug: ["tomato", "carrot", "radish", "garlic"].sample
|
||||
))
|
||||
pointer_id: 0,
|
||||
openfarm_slug: ["tomato", "carrot", "radish", "garlic"].sample)
|
||||
end
|
||||
|
||||
POINT_COUNT.times do
|
||||
Point.create(
|
||||
device: u.device,
|
||||
GenericPointer.create(device: u.device,
|
||||
x: rand(40...970) + rand(40...970),
|
||||
y: rand(40...470) + rand(40...470),
|
||||
z: 5,
|
||||
radius: (rand(1...150) + rand(1...150)) / 20,
|
||||
pointer: GenericPointer.new(),
|
||||
pointer_id: 0,
|
||||
meta: {
|
||||
created_by: "plant-detection",
|
||||
color: (Sequence::COLORS + [nil]).sample
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
SELECT
|
||||
points.x as x,
|
||||
points.y as y,
|
||||
points.z as z,
|
||||
(edge_nodes.value)::int as point_id,
|
||||
points.pointer_type as pointer_type,
|
||||
points.name as pointer_name,
|
||||
sequences.id as sequence_id,
|
||||
sequences.name as sequence_name,
|
||||
edge_nodes.id as edge_node_id
|
||||
FROM "edge_nodes"
|
||||
INNER JOIN "sequences" ON edge_nodes.sequence_id=sequences.id
|
||||
INNER JOIN "points" ON (edge_nodes.value)::int=points.id
|
||||
WHERE "edge_nodes"."kind" = 'pointer_id';
|
|
@ -0,0 +1,10 @@
|
|||
SELECT
|
||||
tools.id as tool_id,
|
||||
tools.name as tool_name,
|
||||
sequences.name as sequence_name,
|
||||
sequences.id as sequence_id,
|
||||
sequences.device_id as device_id
|
||||
FROM "edge_nodes"
|
||||
INNER JOIN "sequences" ON sequences.id=sequences.id
|
||||
INNER JOIN "tools" ON (edge_nodes.value)::int=tools.id
|
||||
WHERE "edge_nodes"."kind" = 'tool_id';
|
Loading…
Reference in New Issue