Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
committing data by bin id now
Browse files Browse the repository at this point in the history
  • Loading branch information
aastronautss committed Apr 14, 2017
1 parent 7c5f03c commit 739e075
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 35 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Expand Up @@ -12,6 +12,7 @@ gem 'pg', '~> 0.18'
gem 'puma', '~> 3.0'
gem 'sidekiq'

gem 'haml'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
Expand All @@ -31,13 +32,10 @@ group :development, :test do
end

group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -57,6 +57,8 @@ GEM
ffi (1.9.18)
globalid (0.3.7)
activesupport (>= 4.1.0)
haml (4.0.7)
tilt
i18n (0.8.1)
jbuilder (2.6.3)
activesupport (>= 3.0.0, < 5.2)
Expand Down Expand Up @@ -171,6 +173,7 @@ PLATFORMS
DEPENDENCIES
byebug
coffee-rails (~> 4.2)
haml
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/app_bins_controller.rb
@@ -0,0 +1,24 @@
class AppBinsController < ApplicationController
before_action :set_app_bin

def show
end

def new
@app_bin = AppBin.new
end

def create
if @app_bin = AppBin.create
redirect_to @app_bin.reload
else
render :new
end
end

private

def set_app_bin
@app_bin = AppBin.find_by app_key: params[:id]
end
end
5 changes: 3 additions & 2 deletions app/controllers/reports_controller.rb
@@ -1,8 +1,9 @@
class ReportsController < ActionController::API
def create
@app_bin = AppBin.find_by app_key: params[:bin_id]
payload = report_params
report_klass = payload[:type].classify.constantize
@report = report_klass.new payload[:data]
report_table = payload[:type].tableize
@report = @app_bin.send(report_table).build payload[:data]

@report.save
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
@@ -1,2 +1,2 @@
class ApplicationHelper
module ApplicationHelper
end
16 changes: 16 additions & 0 deletions app/models/app_bin.rb
@@ -0,0 +1,16 @@
class AppBin < ApplicationRecord
has_many :cycle_transactions
has_many :system_health_samples

before_create :generate_app_key

def to_param
app_key
end

private

def generate_app_key
self.app_key = SecureRandom.urlsafe_base64
end
end
1 change: 1 addition & 0 deletions app/models/cycle_transaction.rb
@@ -1,5 +1,6 @@
class CycleTransaction < ApplicationRecord
has_many :transaction_events
belongs_to :app_bin

after_create :create_transaction_events

Expand Down
1 change: 1 addition & 0 deletions app/models/system_health_sample.rb
@@ -1,2 +1,3 @@
class SystemHealthSample < ApplicationRecord
belongs_to :app_bin
end
2 changes: 2 additions & 0 deletions app/views/app_bins/new.html.haml
@@ -0,0 +1,2 @@
= form_for @app_bin do |f|
= f.submit 'Create a new bin'
1 change: 1 addition & 0 deletions app/views/app_bins/show.html.haml
@@ -0,0 +1 @@
= @app_bin.to_param
14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

10 changes: 10 additions & 0 deletions app/views/layouts/application.html.haml
@@ -0,0 +1,10 @@
!!!5
%html
%head
%title Tracebin
= csrf_meta_tags
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'

%body
= yield
13 changes: 0 additions & 13 deletions app/views/layouts/mailer.html.erb

This file was deleted.

9 changes: 9 additions & 0 deletions app/views/layouts/mailer.html.haml
@@ -0,0 +1,9 @@
!!!5
%html
%head
%meta(http-equiv="Content-Type" content="text/html; charset=utf-8")
%style
-# Email styles need to be inline
%body
= yield
1 change: 0 additions & 1 deletion app/views/layouts/mailer.text.erb

This file was deleted.

1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.haml
@@ -0,0 +1 @@
= yield
3 changes: 3 additions & 0 deletions config/routes.rb
@@ -1,3 +1,6 @@
Rails.application.routes.draw do
root to: 'app_bins#new'

resources :reports, only: [:create]
resources :app_bins, only: [:show, :create]
end
11 changes: 11 additions & 0 deletions db/migrate/20170414143330_create_app_bins.rb
@@ -0,0 +1,11 @@
class CreateAppBins < ActiveRecord::Migration[5.0]
def change
create_table :app_bins do |t|
t.string :app_key, unique: true, index: true

t.timestamps
end

add_reference :cycle_transactions, :app_bin, foreign_key: true, index: true
end
end
@@ -0,0 +1,5 @@
class AddAppBinReferenceToSystemHealthSamples < ActiveRecord::Migration[5.0]
def change
add_reference :system_health_samples, :app_bin, foreign_key: true, index: true
end
end
15 changes: 14 additions & 1 deletion db/schema.rb
Expand Up @@ -10,11 +10,18 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170413204947) do
ActiveRecord::Schema.define(version: 20170414154850) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "app_bins", force: :cascade do |t|
t.string "app_key"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["app_key"], name: "index_app_bins_on_app_key", using: :btree
end

create_table "cycle_transactions", force: :cascade do |t|
t.string "transaction_type"
t.string "name"
Expand All @@ -24,16 +31,22 @@
t.jsonb "events"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "app_bin_id"
t.index ["app_bin_id"], name: "index_cycle_transactions_on_app_bin_id", using: :btree
end

create_table "system_health_samples", force: :cascade do |t|
t.datetime "sampled_at"
t.jsonb "metrics"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "app_bin_id"
t.index ["app_bin_id"], name: "index_system_health_samples_on_app_bin_id", using: :btree
end

# Could not dump table "transaction_events" because of following StandardError
# Unknown type 'transaction_event_type' for column 'event_type'

add_foreign_key "cycle_transactions", "app_bins"
add_foreign_key "system_health_samples", "app_bins"
end

0 comments on commit 739e075

Please sign in to comment.