Slide 1

Slide 1 text

Crushing It With Rake Tasks RailsConf 2016 @barrettclark

Slide 2

Slide 2 text

Barrett Clark RailsConf 2016 @barrettclark

Slide 3

Slide 3 text

RailsConf 2016 @barrettclark

Slide 4

Slide 4 text

rake RailsConf 2016 @barrettclark

Slide 5

Slide 5 text

rake talk RailsConf 2016 @barrettclark

Slide 6

Slide 6 text

Rake = Ruby make Scripting utility to streamline tedious tasks. RailsConf 2016 @barrettclark

Slide 7

Slide 7 text

RailsConf 2016 @barrettclark

Slide 8

Slide 8 text

RailsConf 2016 @barrettclark

Slide 9

Slide 9 text

1 RailsConf 2016 @barrettclark

Slide 10

Slide 10 text

Database Migrations Rails' killer feature https://flic.kr/p/zfTshW RailsConf 2016 @barrettclark

Slide 11

Slide 11 text

class CreatePosts < ActiveRecord::Migration[5.0] def change create_table :posts do |t| t.string :title t.string :body t.timestamps end end end RailsConf 2016 @barrettclark

Slide 12

Slide 12 text

bundle exec rake db:migrate RailsConf 2016 @barrettclark

Slide 13

Slide 13 text

$ bundle exec rake db:migrate == 20160418142215 CreatePosts: migrating ====================================== -- create_table(:posts) -> 0.0180s == 20160418142215 CreatePosts: migrated (0.0181s) ============================= RailsConf 2016 @barrettclark

Slide 14

Slide 14 text

I changed my mind... RailsConf 2016 @barrettclark

Slide 15

Slide 15 text

class CreatePosts < ActiveRecord::Migration[5.0] def change create_table :posts do |t| t.string :title t.string :body t.string :permalink t.timestamps end end end RailsConf 2016 @barrettclark

Slide 16

Slide 16 text

RailsConf 2016 @barrettclark

Slide 17

Slide 17 text

bundle exec rake db:rollback RailsConf 2016 @barrettclark

Slide 18

Slide 18 text

$ bundle exec rake db:rollback == 20160418142215 CreatePosts: reverting ====================================== -- drop_table(:posts) -> 0.0094s == 20160418142215 CreatePosts: reverted (0.0137s) ============================= RailsConf 2016 @barrettclark

Slide 19

Slide 19 text

bundle exec rake db:migrate:redo RailsConf 2016 @barrettclark

Slide 20

Slide 20 text

$ bundle exec rake db:migrate:redo == 20160418142215 CreatePosts: reverting ====================================== -- drop_table(:posts) -> 0.0094s == 20160418142215 CreatePosts: reverted (0.0137s) ============================= == 20160418142215 CreatePosts: migrating ====================================== -- create_table(:posts) -> 0.0135s == 20160418142215 CreatePosts: migrated (0.0139s) ============================= RailsConf 2016 @barrettclark

Slide 21

Slide 21 text

I changed my mind... RailsConf 2016 @barrettclark

Slide 22

Slide 22 text

class CreatePosts < ActiveRecord::Migration[5.0] def change create_table :posts do |t| t.string :title t.string :body t.string :permalink t.timestamps end add_index :posts, :permalink end end RailsConf 2016 @barrettclark

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

bundle exec rake db:drop db:create db:migrate RailsConf 2016 @barrettclark

Slide 25

Slide 25 text

Q: CAN I CHANGE AND RERUN A MIGRATION? A: IT DEPENDS RailsConf 2016 @barrettclark

Slide 26

Slide 26 text

DB Rollback Limitations • New fields are OK • New objects (index, foreign key, etc) are not OK • DO NOT change any migration you've pushed RailsConf 2016 @barrettclark

Slide 27

Slide 27 text

Barrett Clark I'll tweak a migration when I'm first creating something. After that changes get their own migration. RailsConf 2016 @barrettclark

Slide 28

Slide 28 text

2 RailsConf 2016 @barrettclark

Slide 29

Slide 29 text

Advanced Database Seeding https://flic.kr/p/85PkBT RailsConf 2016 @barrettclark

Slide 30

Slide 30 text

# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) RailsConf 2016 @barrettclark

Slide 31

Slide 31 text

# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) Post.where( :title => "First Blog Post", :body => "This is the body of the post.", :permalink => "http://localhost:3000" ).first_or_create RailsConf 2016 @barrettclark

Slide 32

Slide 32 text

bundle exec rake db:migrate db:seed RailsConf 2016 @barrettclark

Slide 33

Slide 33 text

require 'csv' CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end namespace :db do namespace :seed do desc "Import airport data" task :import_airports => :environment do if Airport.count == 0 filename = Rails.root.join('db', 'data_files', 'airports.csv') CSV.foreach(filename, :headers => true, :header_converters => :symbol, :converters => [:blank_to_nil]) do |row| Airport.create(row.to_hash) end end end end end RailsConf 2016 @barrettclark

Slide 34

Slide 34 text

require 'csv' CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end namespace :db do namespace :seed do desc "Import airport data" task :import_airports => :environment do if Airport.count == 0 filename = Rails.root.join('db', 'data_files', 'airports.csv') CSV.foreach(filename, :headers => true, :header_converters => :symbol, :converters => [:blank_to_nil]) do |row| Airport.create(row.to_hash) end end end end end RailsConf 2016 @barrettclark

Slide 35

Slide 35 text

require 'csv' CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end namespace :db do namespace :seed do desc "Import airport data" task :import_airports => :environment do if Airport.count == 0 filename = Rails.root.join('db', 'data_files', 'airports.csv') CSV.foreach(filename, :headers => true, :header_converters => :symbol, :converters => [:blank_to_nil]) do |row| Airport.create(row.to_hash) end end end end end RailsConf 2016 @barrettclark

Slide 36

Slide 36 text

require 'csv' CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end namespace :db do namespace :seed do desc "Import airport data" task :import_airports => :environment do if Airport.count == 0 filename = Rails.root.join('db', 'data_files', 'airports.csv') CSV.foreach(filename, :headers => true, :header_converters => :symbol, :converters => [:blank_to_nil]) do |row| Airport.create(row.to_hash) end end end end end RailsConf 2016 @barrettclark

Slide 37

Slide 37 text

require 'csv' CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end namespace :db do namespace :seed do desc "Import airport data" task :import_airports => :environment do if Airport.count == 0 filename = Rails.root.join('db', 'data_files', 'airports.csv') CSV.foreach(filename, :headers => true, :header_converters => :symbol, :converters => [:blank_to_nil]) do |row| Airport.create(row.to_hash) end end end end end RailsConf 2016 @barrettclark

Slide 38

Slide 38 text

require 'csv' CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end namespace :db do namespace :seed do desc "Import airport data" task :import_airports => :environment do if Airport.count == 0 filename = Rails.root.join('db', 'data_files', 'airports.csv') CSV.foreach(filename, :headers => true, :header_converters => :symbol, :converters => [:blank_to_nil]) do |row| Airport.create(row.to_hash) end end end end end RailsConf 2016 @barrettclark

Slide 39

Slide 39 text

require 'csv' CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end namespace :db do namespace :seed do desc "Import airport data" task :import_airports => :environment do if Airport.count == 0 filename = Rails.root.join('db', 'data_files', 'airports.csv') CSV.foreach(filename, :headers => true, :header_converters => :symbol, :converters => [:blank_to_nil]) do |row| Airport.create(row.to_hash) end end end end end RailsConf 2016 @barrettclark

Slide 40

Slide 40 text

bundle exec rake db:seed:import_airports RailsConf 2016 @barrettclark

Slide 41

Slide 41 text

3 RailsConf 2016 @barrettclark

Slide 42

Slide 42 text

Too Much Log sad trombone https://flic.kr/p/6e5eJG RailsConf 2016 @barrettclark

Slide 43

Slide 43 text

$ ls -lh log/ total 12345 -rw-r--r-- 1 barrettclark staff 2.2M Feb 3 2015 development.log -rw-r--r-- 1 barrettclark staff 105K Jan 29 2015 newrelic_agent.log -rw-r--r-- 1 barrettclark staff 99M Jan 29 2015 test.log RailsConf 2016 @barrettclark

Slide 44

Slide 44 text

bundle exec rake log:clear RailsConf 2016 @barrettclark

Slide 45

Slide 45 text

bundle exec rake db:migrate db:seed log:clear RailsConf 2016 @barrettclark

Slide 46

Slide 46 text

4 RailsConf 2016 @barrettclark

Slide 47

Slide 47 text

Documentation Knowing is half the battle https://flic.kr/p/9Lcbki RailsConf 2016 @barrettclark

Slide 48

Slide 48 text

bundle exec rake notes RailsConf 2016 @barrettclark

Slide 49

Slide 49 text

$ bundle exec rake notes app/models/post.rb: * [2] [TODO] Example todo * [3] [FIXME] This is an example FIXME db/seeds.rb: * [9] [TODO] Need some Post seeds RailsConf 2016 @barrettclark

Slide 50

Slide 50 text

bundle exec rake routes RailsConf 2016 @barrettclark

Slide 51

Slide 51 text

AirportTravelerServer::Application.routes.draw do get "gate/manifest" get "gate/passenger" resources :readings root 'readings#index' end RailsConf 2016 @barrettclark

Slide 52

Slide 52 text

$ bundle exec rake routes Prefix Verb URI Pattern Controller#Action gate_manifest GET /gate/manifest(.:format) gate#manifest gate_passenger GET /gate/passenger(.:format) gate#passenger readings GET /readings(.:format) readings#index POST /readings(.:format) readings#create new_reading GET /readings/new(.:format) readings#new edit_reading GET /readings/:id/edit(.:format) readings#edit reading GET /readings/:id(.:format) readings#show PATCH /readings/:id(.:format) readings#update PUT /readings/:id(.:format) readings#update DELETE /readings/:id(.:format) readings#destroy root GET / readings#index RailsConf 2016 @barrettclark

Slide 53

Slide 53 text

$ bundle exec rake routes | grep gate gate_manifest GET /gate/manifest(.:format) gate#manifest gate_passenger GET /gate/passenger(.:format) gate#passenger RailsConf 2016 @barrettclark

Slide 54

Slide 54 text

5 RailsConf 2016 @barrettclark

Slide 55

Slide 55 text

Upgrade Rails sorcery! http://www.jakehird.com/wp-content/uploads/2011/04/lolcat-server.jpg RailsConf 2016 @barrettclark

Slide 56

Slide 56 text

bundle exec rake rails:update Rails 4 RailsConf 2016 @barrettclark

Slide 57

Slide 57 text

bundle exec rake app:update Rails 5 RailsConf 2016 @barrettclark

Slide 58

Slide 58 text

$ bundle exec rake rails:update identical config/boot.rb exist config identical config/routes.rb identical config/application.rb identical config/environment.rb conflict config/secrets.yml Overwrite /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/secrets.yml? (enter "h" for help) [Ynaqdh] n skip config/secrets.yml identical config/cable.yml identical config/puma.rb exist config/environments identical config/environments/development.rb Overwrite /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb? (enter "h" for help) [Ynaqdh] d --- /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb 2016-04-18 08:23:59.000000000 -0500 +++ /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb20160419-81872-16xjoaj 2016-04-19 22:47:56.000000000 -0500 @@ -65,7 +65,7 @@ # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "RailsConf2016_#{Rails.env}" + # config.active_job.queue_name_prefix = "rails_conf2016_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. Retrying... Overwrite /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb? (enter "h" for help) [Ynaqdh] Y RailsConf 2016 @barrettclark

Slide 59

Slide 59 text

$ bundle exec rake rails:update identical config/boot.rb exist config identical config/routes.rb identical config/application.rb identical config/environment.rb conflict config/secrets.yml Overwrite /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/secrets.yml? (enter "h" for help) [Ynaqdh] n skip config/secrets.yml identical config/cable.yml identical config/puma.rb exist config/environments identical config/environments/development.rb Overwrite /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb? (enter "h" for help) [Ynaqdh] d --- /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb 2016-04-18 08:23:59.000000000 -0500 +++ /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb20160419-81872-16xjoaj 2016-04-19 22:47:56.000000000 -0500 @@ -65,7 +65,7 @@ # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "RailsConf2016_#{Rails.env}" + # config.active_job.queue_name_prefix = "rails_conf2016_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. Retrying... Overwrite /Volumes/Card/Projects/SCRATCH/RUBY/RailsConf2016/config/environments/production.rb? (enter "h" for help) [Ynaqdh] Y RailsConf 2016 @barrettclark

Slide 60

Slide 60 text

Y - yes, overwrite n - no, do not overwrite a - all, overwrite this and all others q - quit, abort d - diff, show the differences between the old and the new h - help, show this help RailsConf 2016 @barrettclark

Slide 61

Slide 61 text

6 RailsConf 2016 @barrettclark

Slide 62

Slide 62 text

Not Just For Rails https://flic.kr/p/4zUrP9 RailsConf 2016 @barrettclark

Slide 63

Slide 63 text

desc "Say hello" task :hello do puts "Hello" end RailsConf 2016 @barrettclark

Slide 64

Slide 64 text

$ rake hello Hello RailsConf 2016 @barrettclark

Slide 65

Slide 65 text

namespace :railsconf do desc "Say hello" task :hello do puts "Hello" end desc "Say world" task :world do puts "World!" end end RailsConf 2016 @barrettclark

Slide 66

Slide 66 text

$ rake railsconf:hello Hello $ rake railsconf:world World! RailsConf 2016 @barrettclark

Slide 67

Slide 67 text

namespace :railsconf do desc "Say hello" task :hello do puts "Hello" end desc "Say world" task :world do puts "World!" end desc "Say hello world" task :phrase => [:hello, :world] end RailsConf 2016 @barrettclark

Slide 68

Slide 68 text

$ rake railsconf:phrase Hello World! RailsConf 2016 @barrettclark

Slide 69

Slide 69 text

namespace :railsconf do desc "Say hello" task :hello do puts "Hello" end desc "Say world" task :world do puts "World!" end desc "Say hello world" task :phrase => [:hello, :world] desc "Take parameter" task :custom_hello, [:name] do |t, args| puts "Hello, #{args[:name]}" end end RailsConf 2016 @barrettclark

Slide 70

Slide 70 text

$ rake railsconf:custom_hello[Barrett] Hello, Barrett RailsConf 2016 @barrettclark

Slide 71

Slide 71 text

require "rubygems" require "bundler" require "rake" Bundler.require load "Rakefile" Rake::Task["railsconf:variable"].invoke("Barrett") RailsConf 2016 @barrettclark

Slide 72

Slide 72 text

$ bundle exec ruby rake_include.rb Hello, Barrett RailsConf 2016 @barrettclark

Slide 73

Slide 73 text

namespace :railsconf do desc "Say hello" task :hello do puts "Hello" end desc "Say world" task :world do puts "World!" end desc "Say hello world" task :phrase => [:hello, :world] desc "Take parameter" task :custom_hello, [:name] do |t, args| puts "Hello, #{args[:name]}" end end task :default => ["railsconf:hello"] RailsConf 2016 @barrettclark

Slide 74

Slide 74 text

$ rake Hello RailsConf 2016 @barrettclark

Slide 75

Slide 75 text

$ rake -T rake railsconf:custom_hello[name] # Take parameter rake railsconf:hello # Say hello rake railsconf:phrase # Say hello world rake railsconf:world # Say world RailsConf 2016 @barrettclark

Slide 76

Slide 76 text

rake about # List versions of all Rails frameworks and the environment rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databas... rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in ... rake db:environment:set # Set the environment value for the database rake db:fixtures:load # Loads fixtures into the current environment's database rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog) rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n) rake db:schema:cache:clear # Clears a db/schema_cache.dump file rake db:schema:cache:dump # Creates a db/schema_cache.dump file rake db:schema:dump # Creates a db/schema.rb file that is portable against any DB supported by Active Record rake db:schema:load # Loads a schema.rb file into the database rake db:seed # Loads the seed data from db/seeds.rb rake db:setup # Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first) rake db:structure:dump # Dumps the database structure to db/structure.sql rake db:structure:load # Recreates the databases from the structure.sql file rake db:version # Retrieves the current schema version number rake dev:cache # Toggle development mode caching on/off rake initializers # Print out all defined initializers in the order they are invoked by Railss | rake log:clear # Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development) rake middleware # Prints out your Rack middleware stack rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus) rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM rake rails:template # Applies the template supplied by LOCATION=(/path/to/template) or URL rake rails:update # Update configs and some other initially generated files (or use just update:configs or update:bin) rake restart # Restart app by touching tmp/restart.txt rake routes # Print out all defined routes in match order, with names rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions) rake stats # Report code statistics (KLOCs, etc) from the application or engine rake test # Runs all tests in test folder rake test:db # Run tests quickly, but also reset db rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6 rake tmp:clear # Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear) rake tmp:create # Creates tmp directories for cache, sockets, and pids RailsConf 2016 @barrettclark

Slide 77

Slide 77 text

" ============================================================================ " Netrw Directory Listing (netrw v155) " /Users/barrettclark/.rvm/gems/ruby-2.2.3@RailConf2016/gems/railties-5.0.0.beta3/lib/rails/tasks " Sorted by name " Sort sequence: [\/]$,\,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$ " Quick Help: :help -:go up dir D:delete R:rename s:sort-by x:special " ============================================================================== ../ ./ annotations.rake dev.rake engine.rake framework.rake initializers.rake log.rake middleware.rake misc.rake restart.rake routes.rake statistics.rake tmp.rake RailsConf 2016 @barrettclark

Slide 78

Slide 78 text

namespace :log do desc "Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)" task :clear do log_files.each do |file| clear_log_file(file) end end def log_files if ENV['LOGS'] == 'all' FileList["log/*.log"] elsif ENV['LOGS'] log_files_to_truncate(ENV['LOGS']) else log_files_to_truncate("development,test,production") end end def log_files_to_truncate(envs) envs.split(',') .map { |file| "log/#{file.strip}.log" } .select { |file| File.exist?(file) } end def clear_log_file(file) f = File.open(file, "w") f.close end end RailsConf 2016 @barrettclark

Slide 79

Slide 79 text

Streamlining Tedium RailsConf 2016 @barrettclark

Slide 80

Slide 80 text

Rake All The Things Streamline tedium RailsConf 2016 @barrettclark

Slide 81

Slide 81 text

$ rails g task Usage: rails generate task NAME [action action] [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated applications) Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Description: Stubs out a new Rake task. Pass the namespace name, and a list of tasks as arguments. This generates a task file in lib/tasks. Example: `rails generate task feeds fetch erase add` Task: lib/tasks/feeds.rake RailsConf 2016 @barrettclark

Slide 82

Slide 82 text

$ rails g task db streamlined create lib/tasks/db.rake RailsConf 2016 @barrettclark

Slide 83

Slide 83 text

namespace :db do desc "TODO" task streamlined: :environment do end end RailsConf 2016 @barrettclark

Slide 84

Slide 84 text

namespace :db do desc "db:migrate, db:seed, log:clear tasks streamlined" task :streamlined => ["db:migrate", "db:seed", "log:clear"] end RailsConf 2016 @barrettclark

Slide 85

Slide 85 text

$ bundle exec rake -T db rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config) rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config) rake db:environment:set # Set the environment value for the database rake db:fixtures:load # Loads fixtures into the current environment's database rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog) rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n) rake db:schema:cache:clear # Clears a db/schema_cache.dump file rake db:schema:cache:dump # Creates a db/schema_cache.dump file rake db:schema:dump # Creates a db/schema.rb file that is portable against any DB supported by Active Record rake db:schema:load # Loads a schema.rb file into the database rake db:seed # Loads the seed data from db/seeds.rb rake db:setup # Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first) rake db:streamlined # db:migrate, db:seed, log:clear tasks streamlined rake db:structure:dump # Dumps the database structure to db/structure.sql rake db:structure:load # Recreates the databases from the structure.sql file rake db:version # Retrieves the current schema version number rake test:db # Run tests quickly, but also reset db RailsConf 2016 @barrettclark

Slide 86

Slide 86 text

⭐ $ bundle exec rake db:streamlined == 20160418142215 CreatePosts: migrating ====================================== -- create_table(:posts) -> 0.0120s == 20160418142215 CreatePosts: migrated (0.0122s) ============================= $ ls -lh log/ total 0 -rw-r--r-- 1 barrettclark staff 0B Apr 28 17:25 development.log RailsConf 2016 @barrettclark

Slide 87

Slide 87 text

Streamlining Tedium • Calculate auth token • Docker management (in Fig days) • Load data into a database • Seed from CSV • Full production database RailsConf 2016 @barrettclark

Slide 88

Slide 88 text

namespace :db do namespace :heroku do desc "capture DB Backup" task :capture_backup => :environment do if Rails.env == 'development' Bundler.with_clean_env do system "heroku pg:backups capture" end end end desc "Pull DB Backup" task :download_backup => :capture_backup do if Rails.env == 'development' Bundler.with_clean_env do system "curl -o latest.dump `heroku pg:backups public-url`" end end end desc "Load the PROD database from Heroku to the local dev database" task :load => :download_backup do if Rails.env == 'development' Bundler.with_clean_env do config = Rails.configuration.database_configuration[Rails.env] system <<-CMD pg_restore --verbose --clean --no-acl --no-owner -h localhost \ -U #{config["username"]} -d #{config["database"]} latest.dump rm -rf latest.dump CMD end end end end end RailsConf 2016 @barrettclark

Slide 89

Slide 89 text

desc "capture DB Backup" task :capture_backup => :environment do if Rails.env == 'development' Bundler.with_clean_env do system "heroku pg:backups capture" end end end RailsConf 2016 @barrettclark

Slide 90

Slide 90 text

desc "Pull DB Backup" task :download_backup => :capture_backup do if Rails.env == 'development' Bundler.with_clean_env do system "curl -o latest.dump `heroku pg:backups public-url`" end end end RailsConf 2016 @barrettclark

Slide 91

Slide 91 text

desc "Load the PROD database from Heroku to the local dev database" task :load => :download_backup do if Rails.env == 'development' Bundler.with_clean_env do config = Rails.configuration.database_configuration[Rails.env] system <<-CMD pg_restore --verbose --clean --no-acl --no-owner -h localhost \ -U #{config["username"]} -d #{config["database"]} latest.dump rm -rf latest.dump CMD end end end RailsConf 2016 @barrettclark

Slide 92

Slide 92 text

namespace :db do namespace :heroku do desc "capture DB Backup" task :capture_backup => :environment do if Rails.env == 'development' Bundler.with_clean_env do system "heroku pg:backups capture" end end end desc "Pull DB Backup" task :download_backup => :capture_backup do if Rails.env == 'development' Bundler.with_clean_env do system "curl -o latest.dump `heroku pg:backups public-url`" end end end desc "Load the PROD database from Heroku to the local dev database" task :load => :download_backup do if Rails.env == 'development' Bundler.with_clean_env do config = Rails.configuration.database_configuration[Rails.env] system <<-CMD pg_restore --verbose --clean --no-acl --no-owner -h localhost \ -U #{config["username"]} -d #{config["database"]} latest.dump rm -rf latest.dump CMD end end end end end RailsConf 2016 @barrettclark

Slide 93

Slide 93 text

Standard Security Warning RailsConf 2016 @barrettclark

Slide 94

Slide 94 text

Recap • Database management • Project maintenance • Plain old ruby projects RailsConf 2016 @barrettclark

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

Questions? Let's talk RailsConf 2016 @barrettclark

Slide 97

Slide 97 text

DATA VISUALIZATION TOOLKIT CLARK exceptional elegance made Ruby on Rails meworks, it can be l, Second Edition, is eloper Michael Hartl of your own complete web development. using Twitter’s ng Sprockets and Sass; d RSpec; better auto- hentication n to Gherkin o for the essential d when developing ue solves a real-world that’s simple enough r your previous web ue Rails mastery. ment ow to pattern e mic ones elopers need ms, including at GitHub $44.99 US / $46.99 CANADA i n f o r m i t . c o m / r u b y i n f o r m i t . c o m / a w r u b y . r a i l s t u t o r i a l . o r g “Ruby on Rails™ Tutorial by Michael Hartl has become a must-read for developers learning how to build Rails apps.” — PETER COOPER, Editor of Ruby Inside MICHAEL HARTL is a programmer, educator, and entrepreneur. He wrote the first edition of Ruby on Rails™ Tutorial (Addison-Wesley, 2011), coauthored RailsSpace (Addison-Wesley, 2008), and was cofounder and lead developer of Insoshi, a popular social networking platform based on Rails. He previously taught theoretical and computational physics at the California Institute of Technology, earning the Caltech Lifetime Achievement Award for Excellence in Teaching. Michael is a graduate of Harvard College, holds a Ph.D. in physics from Caltech, and is an alumnus of the Y Combinator entrepreneur program. DATA VISUALIZATION TOOLKIT A d d i s o n - W e s l e y P r o f e s s i o n a l R u b y S e r i e s Using JavaScript, Rails, and Postgres to Present Data and Geospatial Information BARRETT AUSTIN CLARK RailsConf 2016 @barrettclark

Slide 98

Slide 98 text

Thank you RailsConf 2016 @barrettclark