diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2022-10-02 20:39:06 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2022-10-02 20:39:06 +0000 |
commit | 0ab2bb8647a08b381ed2eb94f6763aa0ad71668f (patch) | |
tree | 71cf260cd494bb73e37b53c65901e34be81bd0cf /db | |
parent | da402cfe189b42cabb24b349ae9784f0e2d91a4c (diff) | |
download | redmine-0ab2bb8647a08b381ed2eb94f6763aa0ad71668f.tar.gz redmine-0ab2bb8647a08b381ed2eb94f6763aa0ad71668f.zip |
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
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20221002193055_delete_orphaned_query_and_role_from_queries_roles.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/db/migrate/20221002193055_delete_orphaned_query_and_role_from_queries_roles.rb b/db/migrate/20221002193055_delete_orphaned_query_and_role_from_queries_roles.rb new file mode 100644 index 000000000..aa86450a2 --- /dev/null +++ b/db/migrate/20221002193055_delete_orphaned_query_and_role_from_queries_roles.rb @@ -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 |