chore: API improvements (#3637)
- Unique validations for Inbox members and Team member objects - Move notification processing to Async
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# ref: https://dev.to/nodefiend/rails-migration-adding-a-unique-index-and-deleting-duplicates-5cde
|
||||
|
||||
class AddUniqueIndexOnInboxMembers < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
# partioning the duplicate records and then removing where more than one row is found
|
||||
ActiveRecord::Base.connection.execute('
|
||||
DELETE FROM inbox_members WHERE id IN (SELECT id from (
|
||||
SELECT id, user_id, inbox_id, ROW_NUMBER() OVER w AS rnum FROM inbox_members WINDOW w AS (
|
||||
PARTITION BY inbox_id, user_id ORDER BY id
|
||||
)
|
||||
) t WHERE t.rnum > 1)
|
||||
')
|
||||
add_index :inbox_members, [:inbox_id, :user_id], unique: true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :inbox_members, [:inbox_id, :user_id]
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_12_19_031453) do
|
||||
ActiveRecord::Schema.define(version: 2021_12_21_125545) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
@@ -429,6 +429,7 @@ ActiveRecord::Schema.define(version: 2021_12_19_031453) do
|
||||
t.integer "inbox_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["inbox_id", "user_id"], name: "index_inbox_members_on_inbox_id_and_user_id", unique: true
|
||||
t.index ["inbox_id"], name: "index_inbox_members_on_inbox_id"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user