mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 10:10:04 +08:00
DEV: column dropper class for cleaner removal of superflous columns
Also fixes issues during deploy cause target column was renamed in theme_fields
This commit is contained in:
52
spec/components/column_dropper_spec.rb
Normal file
52
spec/components/column_dropper_spec.rb
Normal file
@ -0,0 +1,52 @@
|
||||
require 'rails_helper'
|
||||
require 'column_dropper'
|
||||
|
||||
describe ColumnDropper do
|
||||
|
||||
def has_column?(table, column)
|
||||
Topic.exec_sql("SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE
|
||||
table_schema = 'public' AND
|
||||
table_name = :table AND
|
||||
column_name = :column
|
||||
",
|
||||
table: table, column: column
|
||||
).to_a.length == 1
|
||||
end
|
||||
|
||||
it "can correctly drop columns after correct delay" do
|
||||
Topic.exec_sql "ALTER TABLE topics ADD COLUMN junk int"
|
||||
name = Topic
|
||||
.exec_sql("SELECT name FROM schema_migration_details LIMIT 1")
|
||||
.getvalue(0,0)
|
||||
|
||||
Topic.exec_sql("UPDATE schema_migration_details SET created_at = :created_at WHERE name = :name",
|
||||
name: name, created_at: 15.minutes.ago)
|
||||
|
||||
dropped_proc_called = false
|
||||
|
||||
ColumnDropper.drop(
|
||||
table: 'topics',
|
||||
after_migration: name,
|
||||
columns: ['junk'],
|
||||
delay: 20.minutes,
|
||||
on_remove: ->(){dropped_proc_called = true}
|
||||
)
|
||||
|
||||
expect(has_column?('topics', 'junk')).to eq(true)
|
||||
expect(dropped_proc_called).to eq(false)
|
||||
|
||||
ColumnDropper.drop(
|
||||
table: 'topics',
|
||||
after_migration: name,
|
||||
columns: ['junk'],
|
||||
delay: 10.minutes,
|
||||
on_remove: ->(){dropped_proc_called = true}
|
||||
)
|
||||
|
||||
expect(has_column?('topics', 'junk')).to eq(false)
|
||||
expect(dropped_proc_called).to eq(true)
|
||||
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user