Sha256: 359fa822a38d48efc04ccc1765809d06e83e2df7957d706de5e766a9877330ab

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

require "bundler/setup"
require "byebug" unless ENV["RACK_ENV"] == "production"
require "rom/sql/rake_task"
require "shellwords"
require_relative "system/<%= config[:underscored_project_name] %>/container"

begin
  require "rspec/core/rake_task"
  RSpec::Core::RakeTask.new :spec
  task default: [:spec]
rescue LoadError
end

def db
  <%= config[:camel_cased_app_name] %>::Container["persistence.db"]
end

namespace :db do
  task :setup do
    <%= config[:camel_cased_app_name] %>::Container.boot :rom
  end

  desc "Prints current schema version"
  task version: :setup do
    version =
      if db.tables.include?(:schema_migrations)
        db[:schema_migrations].order(:filename).last[:filename]
      else
        "not available"
      end

    puts "Current schema version: #{version}"
  end

  desc "Perform migration up to latest migration available"
  task :migrate do
    # Enhance the migration task provided by ROM

    # Once it finishes, dump the db structure
    Rake::Task["db:structure:dump"].execute

    # And print the current migration version
    Rake::Task["db:version"].execute
  end

  namespace :structure do
    desc "Dump database structure to db/structure.sql"
    task :dump do
      if system("which pg_dump", out: File::NULL)
        system(%(pg_dump -s -x -O #{Shellwords.escape(db.url)} > db/structure.sql))
      end
    end
  end

  desc "Load seed data into the database"
  task :seed do
    seed_data = File.join("db", "seed.rb")
    load(seed_data) if File.exist?(seed_data)
  end

  desc "Load a small, representative set of data so that the application can start in a useful state (for development)."
  task :sample_data do
    sample_data = File.join("db", "sample_data.rb")
    load(sample_data) if File.exist?(sample_data)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-web-roda-0.7.3 lib/dry/web/roda/templates/Rakefile.tt
dry-web-roda-0.7.2 lib/dry/web/roda/templates/Rakefile.tt
dry-web-roda-0.7.1 lib/dry/web/roda/templates/Rakefile.tt
dry-web-roda-0.7.0 lib/dry/web/roda/templates/Rakefile.tt