Skip to content

Commit

Permalink
Merge branch 'master' into fix-revoke-with-fx
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan authored Oct 23, 2024
2 parents a55dbe7 + 5652ac4 commit dec87b5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release gems
on:
workflow_dispatch:
push:
tags:
- v*

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch current tag as annotated. See https://github.com/actions/checkout/issues/290
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
- name: Configure RubyGems Credentials
uses: rubygems/configure-rubygems-credentials@main
- name: Publish to RubyGems
run: |
gem install gem-release
gem release
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

- Fix `rails destroy logidze:model SomeModel` not deleting the `fx` trigger file file. ([@tylerhunt][])

- Support sorting of trigger names alphabetically (defaults to false)

```ruby
Logdize.sort_triggers_by_name = true
```

## 1.3.0 (2024-01-09)

- Add retrieving list of versions support. ([@tagirahmad][])
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,16 @@ The `log_data` column has the following format:

If you specify the limit in the trigger definition, then log size will not exceed the specified size. When a new change occurs, and there is no more room for it, the two oldest changes will be merged.

## Ordering of Triggers in schema.rb

By default, when generating `schema.rb`, Rails will order the triggers based on the id's of their respective tables. This can lead to unnecessary changes being made when utilizing `rails db:prepare`, since the ordering of the tables will now be based off the alphabetical ordering (see [#250](https://github.com/palkan/logidze/issues/250) for more details). To force the ordering to be consistent with `rails db:prepare`, Logidze can be configured to order the triggers alphabetically.

```ruby
# config/initializers/logidze.rb

Logidze.sort_triggers_by_name = true
```

## Troubleshooting

### `log_data` is nil when using Rails fixtures
Expand Down
3 changes: 3 additions & 0 deletions lib/logidze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class << self
attr_accessor :ignore_log_data_by_default
# Whether #at should return self or nil when log_data is nil
attr_accessor :return_self_if_log_data_is_empty
# Determines if triggers are sorted by related table id or by name
attr_accessor :sort_triggers_by_name
# Determines what Logidze should do when upgrade is needed (:raise | :warn | :ignore)
attr_reader :on_pending_upgrade

Expand Down Expand Up @@ -68,4 +70,5 @@ def with_logidze_setting(name, value)
self.ignore_log_data_by_default = false
self.return_self_if_log_data_is_empty = true
self.on_pending_upgrade = :ignore
self.sort_triggers_by_name = false
end
13 changes: 13 additions & 0 deletions lib/logidze/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,18 @@ class Engine < Rails::Engine # :nodoc:
end
end
end

initializer "sort triggers by name" do |app|
if config.logidze.sort_triggers_by_name
ActiveSupport.on_load(:active_record) do
require "fx/adapters/postgres/triggers"
Fx::Adapters::Postgres::Triggers.singleton_class.prepend(Module.new do
def all(*args)
super.sort_by(&:name)
end
end)
end
end
end
end
end

0 comments on commit dec87b5

Please sign in to comment.