Skip to content

Commit 7ea82f3

Browse files
committed
fix broken migrations over the years
1 parent 8a844ab commit 7ea82f3

6 files changed

+35
-20
lines changed

db/migrate/20140713043535_create_models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def change
9898
t.text :description
9999

100100
# Map
101-
t.attachment :map
101+
t.string :map
102102

103103
# Culture
104104
t.string :population
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
class AddSrcToImageUploads < ActiveRecord::Migration[4.2]
22
def self.up
3-
add_attachment :image_uploads, :src
4-
end
5-
6-
def self.down
7-
remove_attachment :image_uploads, :src
3+
add_column :image_uploads, :src, :string
84
end
95
end

db/migrate/20180110200009_upgrade_thredded_v0_14_to_v0_15.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,31 @@ def change # rubocop:disable Metrics/MethodLength
8383

8484
private
8585

86+
#def remove_string_limit(table, column, type: :text, indices: [])
87+
# indices.each { |(_, options)| remove_index table, name: options[:name] }
88+
# change_column table, column, type, **{ limit: nil }
89+
# indices.each { |args| add_index table, *args }
90+
#end
91+
8692
def remove_string_limit(table, column, type: :text, indices: [])
87-
indices.each { |(_, options)| remove_index table, name: options[:name] }
93+
indices.each do |index|
94+
if index.is_a?(Hash) && index[:name] # Ensure index is a hash with :name key
95+
puts "Removing index: #{index[:name]}"
96+
remove_index table, name: index[:name]
97+
else
98+
puts "Skipping malformed index entry: #{index.inspect}"
99+
end
100+
end
101+
88102
change_column table, column, type, limit: nil
89-
indices.each { |args| add_index table, *args }
103+
104+
indices.each do |index|
105+
if index.is_a?(Hash) && index[:columns] # Ensure index has required keys
106+
puts "Re-adding index: #{index[:name]}"
107+
add_index table, index[:columns], name: index[:name], unique: index[:unique], length: index[:length]
108+
else
109+
puts "Skipping malformed index entry: #{index.inspect}"
110+
end
111+
end
90112
end
91113
end

db/migrate/20180930063614_upgrade_thredded_v0_15_to_v0_16.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
class UpgradeThreddedV015ToV016 < Thredded::BaseMigration
66
def up
7+
add_column :thredded_topics, :deleted_at, :datetime
8+
79
%i[thredded_user_topic_read_states thredded_user_private_topic_read_states].each do |table_name|
810
add_column table_name, :unread_posts_count, :integer, default: 0, null: false
911
add_column table_name, :read_posts_count, :integer, default: 0, null: false
@@ -21,6 +23,8 @@ def up
2123
end
2224

2325
def down
26+
remove_column :thredded_topics, :deleted_at
27+
2428
remove_column :thredded_user_topic_read_states, :messageboard_id
2529
%i[thredded_user_topic_read_states thredded_user_private_topic_read_states].each do |table|
2630
remove_column table, :unread_posts_count

db/migrate/20210308072329_add_deleted_at_date_times_to_thredded_tables.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class AddDeletedAtDateTimesToThreddedTables < ActiveRecord::Migration[6.0]
22
def change
3-
add_column :thredded_topics, :deleted_at, :datetime
3+
#add_column :thredded_topics, :deleted_at, :datetime
44
add_index :thredded_topics, :deleted_at
55
add_index :thredded_topics, [:deleted_at, :messageboard_id]
66
add_index :thredded_topics, [:deleted_at, :user_id]

db/schema.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
create_table "basil_feedbacks", force: :cascade do |t|
216216
t.integer "basil_commission_id", null: false
217217
t.integer "user_id", null: false
218-
t.integer "score_adjustment"
218+
t.integer "score_adjustment", default: 0
219219
t.datetime "created_at", precision: 6, null: false
220220
t.datetime "updated_at", precision: 6, null: false
221221
t.index ["basil_commission_id"], name: "index_basil_feedbacks_on_basil_commission_id"
@@ -1669,10 +1669,7 @@
16691669
t.integer "content_id"
16701670
t.datetime "created_at", null: false
16711671
t.datetime "updated_at", null: false
1672-
t.string "src_file_name"
1673-
t.string "src_content_type"
1674-
t.bigint "src_file_size"
1675-
t.datetime "src_updated_at"
1672+
t.string "src"
16761673
t.index ["content_type", "content_id"], name: "index_image_uploads_on_content_type_and_content_id"
16771674
t.index ["user_id"], name: "index_image_uploads_on_user_id"
16781675
end
@@ -1941,10 +1938,6 @@
19411938
t.string "name", null: false
19421939
t.string "type_of"
19431940
t.text "description"
1944-
t.string "map_file_name"
1945-
t.string "map_content_type"
1946-
t.integer "map_file_size"
1947-
t.datetime "map_updated_at"
19481941
t.string "population"
19491942
t.string "language"
19501943
t.string "currency"
@@ -3216,7 +3209,7 @@
32163209
t.datetime "updated_at", null: false
32173210
t.boolean "locked", default: false, null: false
32183211
t.index ["messageboard_group_id"], name: "index_thredded_messageboards_on_messageboard_group_id"
3219-
t.index ["slug"], name: "index_thredded_messageboards_on_slug", unique: true
3212+
t.index ["slug"], name: "index_thredded_messageboards_on_slug"
32203213
end
32213214

32223215
create_table "thredded_notifications_for_followed_topics", force: :cascade do |t|
@@ -3291,7 +3284,7 @@
32913284
t.datetime "updated_at", null: false
32923285
t.index ["hash_id"], name: "index_thredded_private_topics_on_hash_id"
32933286
t.index ["last_post_at"], name: "index_thredded_private_topics_on_last_post_at"
3294-
t.index ["slug"], name: "index_thredded_private_topics_on_slug", unique: true
3287+
t.index ["slug"], name: "index_thredded_private_topics_on_slug"
32953288
end
32963289

32973290
create_table "thredded_private_users", force: :cascade do |t|

0 commit comments

Comments
 (0)