Closed developie0610 closed 1 year ago
@djezzzl, any chance you were able to take a look at this?
Hi @developie0610,
Thank you for reporting this!
Hi @toydestroyer,
Thank you for pinging me; it seems I overlooked this.
Could you please help me to understand what the checker should check? That every model with UUID as a primary key have implicit_order_column
defined?
Could you please help me to understand what the checker should check? That every model with UUID as a primary key have implicit_order_column defined?
Yes. That is what we are looking for @djezzzl and I don't see the need for more complications.
Let me know if this is a sensible checker, I am happy to contribute on the actual work since we are the primary user as far as I'm concerned.
Hey @developie0610,
Feel free to make a PR if you have time; however, I'm happy to help if you can't.
Could you give me a minimal code example (model/schema with meaningful code there), though, so I can repeat it in my tests and do a proper checker?
awesome, thanks @djezzzl. I'll contribute the PR. You can refer to this arbitrary setup to verify:
Rails 7
# db/schema.rb
enable_extension "plpgsql"
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
class User < ApplicationRecord
self.implicit_order_column = 'created_at'
end
class CreateUser < ActiveRecord::Migration[7.0]
def change
enable_extension 'pgcrypto'
create_table :users, id: :uuid do |t|
t.string :name
t.timestamps
end
end
end
-> Expected result from User.last
:
SELECT "users".* FROM "users" ORDER BY "users"."created_at" DESC, "users"."id" DESC
Thank you for sharing this!
I'll contribute to the PR.
Great then! Please feel free to ping me for any assistance; if you can't finish, please let me know, and I can do that.
Hi @developie0610,
Thank you for your contribution!
I just released this on 1.7.18. Please have a look.
BTW, could you please fill in the WIKI page?
https://github.com/djezzzl/database_consistency/wiki/implicitorderingchecker
P.S. Have a great weekend!
Hi @djezzzl , I'm working on a project that recently start utilize
uuid
as our primary key for new database's table. We find it's a common pattern to defineimplicit_order_column
(supported Rails >=6) with such tables to maintain the records's order in queries.We have reason to think that this approach would be a common practice compare to using sortable uuid algorithm, and given that we are relying heavily on
database_consistency
, having a checker would be a great resource.