Skip to content

Commit

Permalink
Documentation markup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lvonk committed May 15, 2024
1 parent 9400a4a commit e55e8d5
Showing 1 changed file with 93 additions and 93 deletions.
186 changes: 93 additions & 93 deletions docs/docs/rails-sequent.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,79 +30,78 @@ See the [Rails autoloading and reloading guide](https://guides.rubyonrails.org/a

4) Create `./db/sequent_migrations.rb`. This will contain your `view_schema` migrations.

```ruby
VIEW_SCHEMA_VERSION = 1

class SequentMigrations < Sequent::Migrations::Projectors
def self.version
VIEW_SCHEMA_VERSION
end

def self.versions
{
'1' => [
# List of migrations for version 1
],
}
end
end

```
```ruby
VIEW_SCHEMA_VERSION = 1

class SequentMigrations < Sequent::Migrations::Projectors
def self.version
VIEW_SCHEMA_VERSION
end

def self.versions
{
'1' => [
# List of migrations for version 1
],
}
end
end
```

For a complete overview on how Migrations work in Sequent, check out the [Migrations Guide](/docs/concepts/migrations.html)


5) Add the following snippet to your `Rakefile`

```ruby
# Sequent requires a `SEQUENT_ENV` environment to be set
# next to a `RAILS_ENV`
ENV['SEQUENT_ENV'] = ENV['RAILS_ENV'] ||= 'development'
require 'sequent/rake/migration_tasks'
Sequent::Rake::MigrationTasks.new.register_tasks!
# The dependency of sequent:init on :environment ensures the Rails app is loaded
# when running the sequent migrations. This is needed otherwise
# the sequent initializer - which is required to run these rake tasks -
# doesn't run
task 'sequent:init' => [:environment]
task 'sequent:migrate:init' => [:sequent_db_connect]
task 'sequent_db_connect' do
Sequent::Support::Database.connect!(ENV['SEQUENT_ENV'])
end
# Create custom rake task setting the SEQUENT_MIGRATION_SCHEMAS for
# running the Rails migrations
task :migrate_public_schema do
ENV['SEQUENT_MIGRATION_SCHEMAS'] = 'public'
Rake::Task['db:migrate'].invoke
ENV['SEQUENT_MIGRATION_SCHEMAS'] = nil
end
# Prevent rails db:migrate from being executed directly.
Rake::Task['db:migrate'].enhance([:'sequent:db:dont_use_db_migrate_directly'])
```


**You can't use rails db:migrate directly** anymore since
that will add all the tables of the `view_schema` and `sequent_schema`
to the `schema.rb` file after running a Rails migration. To fix this
the `rails db:migrate` must be wrapped in your own task setting the
environment variable `SEQUENT_MIGRATION_SCHEMAS`.
For safety reasons you can enchance and prepend the `rails db:migrate`
with Sequents `sequent:db:dont_use_db_migrate_directly` Rake task
so running it without `SEQUENT_MIGRATION_SCHEMAS` set will fail.
{: .notice--warning}
```ruby
# Sequent requires a `SEQUENT_ENV` environment to be set
# next to a `RAILS_ENV`
ENV['SEQUENT_ENV'] = ENV['RAILS_ENV'] ||= 'development'

require 'sequent/rake/migration_tasks'

Sequent::Rake::MigrationTasks.new.register_tasks!

# The dependency of sequent:init on :environment ensures the Rails app is loaded
# when running the sequent migrations. This is needed otherwise
# the sequent initializer - which is required to run these rake tasks -
# doesn't run
task 'sequent:init' => [:environment]
task 'sequent:migrate:init' => [:sequent_db_connect]

task 'sequent_db_connect' do
Sequent::Support::Database.connect!(ENV['SEQUENT_ENV'])
end

# Create custom rake task setting the SEQUENT_MIGRATION_SCHEMAS for
# running the Rails migrations
task :migrate_public_schema do
ENV['SEQUENT_MIGRATION_SCHEMAS'] = 'public'
Rake::Task['db:migrate'].invoke
ENV['SEQUENT_MIGRATION_SCHEMAS'] = nil
end

# Prevent rails db:migrate from being executed directly.
Rake::Task['db:migrate'].enhance([:'sequent:db:dont_use_db_migrate_directly'])
```


**You can't use rails db:migrate directly** anymore since
that will add all the tables of the `view_schema` and `sequent_schema`
to the `schema.rb` file after running a Rails migration. To fix this
the `rails db:migrate` must be wrapped in your own task setting the
environment variable `SEQUENT_MIGRATION_SCHEMAS`.
For safety reasons you can enchance and prepend the `rails db:migrate`
with Sequents `sequent:db:dont_use_db_migrate_directly` Rake task
so running it without `SEQUENT_MIGRATION_SCHEMAS` set will fail.
{: .notice--warning}

6) Ensure your `database.yml` contains the schema_search_path:

```yaml
default:
schema_search_path: <%= ENV['SEQUENT_MIGRATION_SCHEMAS'] || 'public, sequent_schema, view_schema' %>
```
```yaml
default:
schema_search_path: <%= ENV['SEQUENT_MIGRATION_SCHEMAS'] || 'public, sequent_schema, view_schema' %>
```
7) Enable eager loading on all environments
Expand All @@ -114,36 +113,37 @@ See the [Rails autoloading and reloading guide](https://guides.rubyonrails.org/a

8) Add `./config/initializers/sequent.rb` containing at least:

```ruby
require_relative '../../db/sequent_migrations'
```ruby
require_relative '../../db/sequent_migrations'
Rails.application.reloader.to_prepare do
Sequent.configure do |config|
config.migrations_class_name = 'SequentMigrations'
config.enable_autoregistration = true
config.event_store_cache_event_types = !Rails.env.development?
config.database_config_directory = 'config'
Rails.application.reloader.to_prepare do
Sequent.configure do |config|
config.migrations_class_name = 'SequentMigrations'
config.enable_autoregistration = true
config.event_store_cache_event_types = !Rails.env.development?
config.database_config_directory = 'config'
# this is the location of your sql files for your view_schema
config.migration_sql_files_directory = 'db/sequent'
end
end
```
**You must** wrap the sequent initializer code in `Rails.application.reloader.to_prepare` because during
initialization, the autoloading hasn't run yet.
# this is the location of your sql files for your view_schema
config.migration_sql_files_directory = 'db/sequent'
end
end
```

**You must** wrap the sequent initializer code in `Rails.application.reloader.to_prepare` because during
initialization, the autoloading hasn't run yet.
{: .notice--warning}

9) Run the following commands to create the `sequent_schema` and `view_schema`

```bash
bundle exec rake sequent:db:create_event_store
bundle exec rake sequent:db:create_view_schema
# only run this when you add or change projectors in SequentMigrations
bundle exec rake sequent:migrate:online
bundle exec rake sequent:migrate:offline
```
```bash
bundle exec rake sequent:db:create_event_store
bundle exec rake sequent:db:create_view_schema
# only run this when you add or change projectors in SequentMigrations
bundle exec rake sequent:migrate:online
bundle exec rake sequent:migrate:offline
```

10) Add the following to application.rb

Expand All @@ -152,9 +152,9 @@ See the [Rails autoloading and reloading guide](https://guides.rubyonrails.org/a
If you for instance load Aggregates inside Controllers or or ActiveJob you have to clear Sequent's Unit Of Work (stored in the Thread.current) yourself.
For the web you can add the following Rack middleware:

```ruby
config.middleware.use Sequent::Util::Web::ClearCache
```
```ruby
config.middleware.use Sequent::Util::Web::ClearCache
```

Otherwise you will need to add a call to `Sequent.aggregate_repository.clear!` somewhere yourself.

Expand Down

0 comments on commit e55e8d5

Please sign in to comment.