Class: ForeignKeyChecker::ZombieResult
- Inherits:
-
Result
- Object
- Result
- ForeignKeyChecker::ZombieResult
show all
- Defined in:
- lib/foreign_key_checker.rb
Instance Attribute Summary collapse
Attributes inherited from Result
#association, #model
Instance Method Summary
collapse
Methods inherited from Result
#from_column, #from_table, #human_relation, #initialize, #inspect, #nullable?, #to_column, #to_table
Instance Attribute Details
#scope ⇒ Object
Returns the value of attribute scope.
77
78
79
|
# File 'lib/foreign_key_checker.rb', line 77
def scope
@scope
end
|
#zombies ⇒ Object
Returns the value of attribute zombies.
77
78
79
|
# File 'lib/foreign_key_checker.rb', line 77
def zombies
@zombies
end
|
Instance Method Details
#delete_sql ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/foreign_key_checker.rb', line 82
def delete_sql
from_t = model.connection.quote_table_name(from_table)
from_c = model.connection.quote_column_name(from_column)
to_t = model.connection.quote_table_name(to_table)
to_c = model.connection.quote_column_name(to_column)
"DELETE FROM #{from_t} WHERE #{from_c} IS NOT NULL AND #{from_c} NOT IN (SELECT * FROM (SELECT #{to_c} FROM #{to_t}) AS t )"
end
|
#message ⇒ Object
109
110
111
|
# File 'lib/foreign_key_checker.rb', line 109
def message
"#{human_relation} with #{zombies} zombies; processed by statement:\n#{sql}\n"
end
|
#migration(set_null: false) ⇒ Object
104
105
106
107
|
# File 'lib/foreign_key_checker.rb', line 104
def migration(set_null: false)
return set_null_migration if set_null
"execute('#{delete_sql}')"
end
|
#set_null_migration ⇒ Object
100
101
102
|
# File 'lib/foreign_key_checker.rb', line 100
def set_null_migration
"execute('#{set_null_sql}')"
end
|
#set_null_sql ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/foreign_key_checker.rb', line 91
def set_null_sql
from_t = model.connection.quote_table_name(from_table)
from_c = model.connection.quote_column_name(from_column)
to_t = model.connection.quote_table_name(to_table)
to_c = model.connection.quote_column_name(to_column)
"UPDATE #{from_t} SET #{from_c} = NULL WHERE #{from_c} IS NOT NULL AND #{from_c} NOT IN (SELECT * FROM (SELECT #{to_c} FROM #{to_t}) AS t )"
end
|
#sql ⇒ Object
78
79
80
|
# File 'lib/foreign_key_checker.rb', line 78
def sql
scope.to_sql
end
|