Browse Source

Delete orphaned query and role ids from habtm join table (#36844).



git-svn-id: https://svn.redmine.org/redmine/trunk@21893 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/5.1.0
Marius Balteanu 1 year ago
parent
commit
0ab2bb8647

+ 14
- 0
db/migrate/20221002193055_delete_orphaned_query_and_role_from_queries_roles.rb View File

@@ -0,0 +1,14 @@
class DeleteOrphanedQueryAndRoleFromQueriesRoles < ActiveRecord::Migration[6.1]
def self.up
queries_roles = "#{Query.table_name_prefix}queries_roles#{Query.table_name_suffix}"
queries = Query.table_name
roles = Role.table_name

ActiveRecord::Base.connection.execute "DELETE FROM #{queries_roles} WHERE query_id NOT IN (SELECT DISTINCT(id) FROM #{queries})"
ActiveRecord::Base.connection.execute "DELETE FROM #{queries_roles} WHERE role_id NOT IN (SELECT DISTINCT(id) FROM #{roles})"
end

def self.down
# no-op
end
end

Loading…
Cancel
Save