You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/tasks/fix_migration_numbers.rake
+22-4
Original file line number
Diff line number
Diff line change
@@ -11,12 +11,30 @@ namespace :redmine_git_hosting do
11
11
puts"old_name : #{old_name}"
12
12
puts"new_name : #{new_name}"
13
13
14
-
query="DELETE FROM #{ActiveRecord::Base.connection.quote_string('schema_migrations')} WHERE #{ActiveRecord::Base.connection.quote_string('version')} = '#{ActiveRecord::Base.connection.quote_string(old_name)}';"
15
-
ActiveRecord::Base.connection.execute(query)
14
+
# Get the old migration name
15
+
query="SELECT * FROM #{ActiveRecord::Base.connection.quote_string('schema_migrations')} WHERE #{ActiveRecord::Base.connection.quote_string('version')} = '#{ActiveRecord::Base.connection.quote_string(old_name)}';"
query="INSERT INTO #{ActiveRecord::Base.connection.quote_string('schema_migrations')} (VERSION) VALUES ('#{ActiveRecord::Base.connection.quote_string(new_name)}');"
18
-
ActiveRecord::Base.connection.execute(query)
18
+
# If present, rename
19
+
if !result.to_a.empty?
20
+
query="DELETE FROM #{ActiveRecord::Base.connection.quote_string('schema_migrations')} WHERE #{ActiveRecord::Base.connection.quote_string('version')} = '#{ActiveRecord::Base.connection.quote_string(old_name)}';"
21
+
ActiveRecord::Base.connection.execute(query)
19
22
23
+
query="INSERT INTO #{ActiveRecord::Base.connection.quote_string('schema_migrations')} (VERSION) VALUES ('#{ActiveRecord::Base.connection.quote_string(new_name)}');"
24
+
ActiveRecord::Base.connection.execute(query)
25
+
else
26
+
# Check the new name is present
27
+
query="SELECT * FROM #{ActiveRecord::Base.connection.quote_string('schema_migrations')} WHERE #{ActiveRecord::Base.connection.quote_string('version')} = '#{ActiveRecord::Base.connection.quote_string(new_name)}';"
0 commit comments