Browse Source

Change loading logic of entire suite in Rakefile

This allows us to bootstrap without having databaseconnections
available.
tags/0.3.0^2
Bèr Kessels 1 year ago
parent
commit
e1192f26e9
3 changed files with 19 additions and 13 deletions
  1. 17
    11
      Rakefile
  2. 1
    1
      app/aggregates/place/place_id.rb
  3. 1
    1
      lib/hours.rb

+ 17
- 11
Rakefile View File

@@ -2,21 +2,27 @@

$LOAD_PATH.unshift '.'

task :event_sourcery do
require 'config/event_sourcery.rb'
end

task :environment do
require 'lib/hours'
end

task :sequel do
require 'dotenv'
Dotenv.load(".env.#{ENV['APP_ENV']}", '.env')

require 'sequel'
require 'sequel-postgis-georuby'
@pg_url = "postgres://#{ENV['DB_USER']}:#{ENV['DB_PASSWORD']}@"\
"#{ENV['DB_HOST']}:#{ENV['DB_PORT']}"
end

desc 'Setup Event Stream Processors'
task setup_processors: :environment do
Hours::Projections::Places::Projector.new.setup
end

desc 'Run Event Stream Processors'
task run_processors: %i[environment event_sourcery] do
task run_processors: :environment do
# Need to disconnect before starting the processors so
# that the forked processes have their own connection / fork safety.
Hours.projections_database.disconnect
@@ -38,12 +44,12 @@ task run_web: :environment do
end

namespace :db do
task create: :environment do
pg_db = Sequel.connect(Hours.config.postgres_database_url)
task create: :sequel do
pg_db = Sequel.connect("#{@pg_url}/postgres")
begin
pg_db.run("CREATE DATABASE #{ENV['DB_NAME']}")
pg_db.disconnect
app_db = Sequel.connect(Hours.config.database_url)
app_db = Sequel.connect("#{@pg_url}/#{ENV['DB_NAME']}")
app_db.run('CREATE EXTENSION postgis')
app_db.run('CREATE EXTENSION hstore')
rescue Sequel::DatabaseError => e
@@ -56,19 +62,19 @@ namespace :db do
end

desc 'Re Create Event Store datatabase and tables'
task event_store: %i[environment event_sourcery] do
task event_store: :environment do
database = EventSourcery::Postgres.config.event_store_database
EventSourcery::Postgres::Schema.create_event_store(db: database)
end

desc 'Re Create Projections database and tables'
task projections: %i[environment event_sourcery] do
task projections: :environment do
Hours::Projections::Places::Projector.new.setup
end
end

namespace :db do
task seed: %i[environment event_sourcery] do
task seed: :environment do
require_relative 'test/support/data_helpers.rb'
Dir['./test/support/workflows/*.rb'].each { |file| require file }


+ 1
- 1
app/aggregates/place/place_id.rb View File

@@ -51,7 +51,7 @@ module Hours
end

def name
properties['name']
properties['name'] || ''
end

def location

+ 1
- 1
lib/hours.rb View File

@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'ap'

require 'event_sourcery'
require 'event_sourcery/postgres'
require 'pathname'
require 'sequel-postgis-georuby'
require 'securerandom'


Loading…
Cancel
Save