diff --git a/CHANGELOG.md b/CHANGELOG.md index 25207a0..cbffac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.5.1] - 2024-09-20 +### Changed +- Use after commit on create instead of after create + ## [1.5.0] - 2024-09-20 ### Added - Added uuid version option diff --git a/Gemfile.lock b/Gemfile.lock index 2151e82..9856eac 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lite-uxid (1.5.0) + lite-uxid (1.5.1) GEM remote: https://rubygems.org/ diff --git a/README.md b/README.md index fe8cb66..8543e2c 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,15 @@ Passable options are: Add the following attribute to all corresponding tables. ```ruby -t.string :uxid, index: { unique: true } +# NOTE: null: true has to be set for HashID's +# since an ID must exist before it gets created. +t.string :uxid, null: false, index: { unique: true } +``` + +If using UUID and your database supports it: + +```ruby +t.uuid :uxid, null: false, index: { unique: true } ``` **Setup** diff --git a/lib/generators/lite/uxid/templates/install.rb b/lib/generators/lite/uxid/templates/install.rb index c881f7d..3680315 100644 --- a/lib/generators/lite/uxid/templates/install.rb +++ b/lib/generators/lite/uxid/templates/install.rb @@ -8,4 +8,5 @@ config.nanoid_size = 21 config.ulid_charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" config.ulid_size = 26 + config.uuid_version = 4 end diff --git a/lib/lite/uxid/record/hashid.rb b/lib/lite/uxid/record/hashid.rb index 36d0abc..dabc2d9 100644 --- a/lib/lite/uxid/record/hashid.rb +++ b/lib/lite/uxid/record/hashid.rb @@ -10,7 +10,9 @@ module Hashid extend ActiveSupport::Concern included do - after_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? } + after_commit :callback_generate_uxid!, + if: proc { respond_to?(:uxid) && !uxid? }, + on: :create end class_methods do diff --git a/lib/lite/uxid/record/nanoid.rb b/lib/lite/uxid/record/nanoid.rb index a348eb6..4816449 100644 --- a/lib/lite/uxid/record/nanoid.rb +++ b/lib/lite/uxid/record/nanoid.rb @@ -10,7 +10,8 @@ module Nanoid extend ActiveSupport::Concern included do - before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? } + before_create :callback_generate_uxid!, + if: proc { respond_to?(:uxid) && !uxid? } end def uxid_prefix diff --git a/lib/lite/uxid/record/ulid.rb b/lib/lite/uxid/record/ulid.rb index 5986397..dc9c087 100644 --- a/lib/lite/uxid/record/ulid.rb +++ b/lib/lite/uxid/record/ulid.rb @@ -10,7 +10,8 @@ module Ulid extend ActiveSupport::Concern included do - before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? } + before_create :callback_generate_uxid!, + if: proc { respond_to?(:uxid) && !uxid? } end private diff --git a/lib/lite/uxid/record/uuid.rb b/lib/lite/uxid/record/uuid.rb index 308df6f..9728634 100644 --- a/lib/lite/uxid/record/uuid.rb +++ b/lib/lite/uxid/record/uuid.rb @@ -10,7 +10,8 @@ module Uuid extend ActiveSupport::Concern included do - before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? } + before_create :callback_generate_uxid!, + if: proc { respond_to?(:uxid) && !uxid? } end private diff --git a/lib/lite/uxid/version.rb b/lib/lite/uxid/version.rb index c35414a..703eb06 100644 --- a/lib/lite/uxid/version.rb +++ b/lib/lite/uxid/version.rb @@ -3,7 +3,7 @@ module Lite module Uxid - VERSION = "1.5.0" + VERSION = "1.5.1" end end