Browse Source

Turn address database into a projection.

feature/region-slug-gone
Bèr Kessels 5 months ago
parent
commit
fbadcd8ac1
5 changed files with 50 additions and 8 deletions
  1. 0
    1
      Makefile
  2. 1
    0
      Rakefile
  3. 1
    1
      app/aggregates/place/address.rb
  4. 48
    0
      app/projections/addresses.rb
  5. 0
    6
      lib/hours.rb

+ 0
- 1
Makefile View File

@@ -39,7 +39,6 @@ _db-setup:
$(CMD_PREFIX) rake db:create
$(CMD_PREFIX) rake db:event_store
$(CMD_PREFIX) rake db:projections
$(CMD_PREFIX) rake db:seed # TODO: don't run seeds on test
@if [ $(APP_ENV) = 'test' ]; then ./bin/seedaddr < test/fixtures/address_sample.csv; fi

_wait:

+ 1
- 0
Rakefile View File

@@ -76,6 +76,7 @@ namespace :db do
desc 'Re Create Projections database and tables'
task projections: :environment do
Hours::Projections::Places::Projector.new.setup
Hours::Projections::Addresses::Projector.new.setup
end
end


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

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

def dataset
Hours.address_database[ADDRESS_TABLE]
Hours.projections_database[ADDRESS_TABLE]
end

def address

+ 48
- 0
app/projections/addresses.rb View File

@@ -0,0 +1,48 @@
# frozen_string_literal: true

module Hours
module Projections
module Addresses
##
# Handles the Places Projection
class Projector
include EventSourcery::Postgres::Projector
ADDRESS_TABLE_NAME = :query_addresses

projector_name :addresses

# Database tables that form the projection.
table ADDRESS_TABLE_NAME do
column :hash, :varchar, null: false, size: 255, primary_key: true
column :number, :varchar, size: 32
column :street, :varchar, size: 255
column :unit, :varchar, size: 255
column :city, :varchar, size: 255
column :district, :varchar, size: 255
column :region, :varchar, size: 255
column :postcode, :varchar, size: 32
column :location, 'geography(POINT)'

index :hash, unique: true
end

def setup
status = super
@db_connection.run(index_gist)
status
end

private

def index_gist
col = :location
name = "#{ADDRESS_TABLE_NAME}_#{col}"
"CREATE INDEX #{name} ON #{ADDRESS_TABLE_NAME} USING GIST(#{col})"
end

# Directly imported with Postgres COPY CMD for now. So no projection
# handler yet.
end
end
end
end

+ 0
- 6
lib/hours.rb View File

@@ -67,12 +67,6 @@ module Hours
EventSourcery::Postgres.config.projections_database
end

def self.address_database
# For now, we're lazy and stick the addresses in the same projections
# database. It could (and probably should) be a separate database.
EventSourcery::Postgres.config.projections_database
end

def self.repository
@repository ||= EventSourcery::Repository.new(
event_source: event_source,

Loading…
Cancel
Save