Getting started
You’ll add Funes to a Rails application and generate a migration that creates the table where Funes stores events. There are two short steps.
Install the gem
Add Funes to your Gemfile:
gem "funes-rails"
Then install the gem:
$ bundle install
Add the events table
Funes stores all events in a single table called event_entries. Generate the migration that creates this table:
$ bin/rails generate funes:install
This command creates a migration file under db/migrate/. Open the file and you’ll see that it sets up the event_entries table with the columns Funes needs:
- the event class
- a stream identifier
- the event attributes, as JSON
- a version number, for concurrency control
- two timestamps:
created_atfor when Funes recorded the event, andoccurred_atfor when the event actually happened
On Postgres, the migration uses jsonb instead of json for the attributes and metainformation columns. The data is the same, but the database can index and query it.
Now run the migration:
$ bin/rails db:migrate
Your events table is ready. Funes will append rows to event_entries as soon as you define your first event stream.