You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20221002193055_delete_orphaned_query_and_role_from_queries_roles.rb 550B

1234567891011121314
  1. class DeleteOrphanedQueryAndRoleFromQueriesRoles < ActiveRecord::Migration[6.1]
  2. def self.up
  3. queries_roles = "#{Query.table_name_prefix}queries_roles#{Query.table_name_suffix}"
  4. queries = Query.table_name
  5. roles = Role.table_name
  6. ActiveRecord::Base.connection.execute "DELETE FROM #{queries_roles} WHERE query_id NOT IN (SELECT DISTINCT(id) FROM #{queries})"
  7. ActiveRecord::Base.connection.execute "DELETE FROM #{queries_roles} WHERE role_id NOT IN (SELECT DISTINCT(id) FROM #{roles})"
  8. end
  9. def self.down
  10. # no-op
  11. end
  12. end