Class: Acta::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/acta/adapters/base.rb

Direct Known Subclasses

Postgres, SQLite

Instance Method Summary collapse

Instance Method Details

#fetch_recordsObject

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/acta/adapters/base.rb', line 54

def fetch_records
  raise NotImplementedError, "#{self.class}#fetch_records"
end

#insert_event(_attributes) ⇒ Object

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/acta/adapters/base.rb', line 50

def insert_event(_attributes)
  raise NotImplementedError, "#{self.class}#insert_event"
end

#install_schema(connection, table_name: :events) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/acta/adapters/base.rb', line 6

def install_schema(connection, table_name: :events)
  uuid_type = uuid_column_type
  json_type = json_column_type

  connection.create_table(table_name) do |t|
    t.send(uuid_type, :uuid, null: false)
    t.string  :event_type, null: false
    t.integer :event_version, null: false, default: 1

    t.string  :stream_type
    t.string  :stream_key
    t.integer :stream_sequence

    t.send(json_type, :payload, null: false)

    t.string :actor_type
    t.string :actor_id
    t.string :source
    t.send(json_type, :metadata)

    t.datetime :occurred_at, null: false
    t.datetime :recorded_at, null: false
  end

  connection.add_index table_name, :uuid, unique: true
  connection.add_index table_name,
                       [ :stream_type, :stream_key, :stream_sequence ],
                       unique: true,
                       where: "stream_type IS NOT NULL",
                       name: "index_events_on_stream_identity"
  connection.add_index table_name, :event_type
  connection.add_index table_name, [ :actor_type, :actor_id ]
  connection.add_index table_name, :source
  connection.add_index table_name, :occurred_at
end

#json_column_typeObject



46
47
48
# File 'lib/acta/adapters/base.rb', line 46

def json_column_type
  :json
end

#uuid_column_typeObject



42
43
44
# File 'lib/acta/adapters/base.rb', line 42

def uuid_column_type
  :string
end