mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 20:08:26 +00:00
SPEC: ensure never remap readonly columns
Follow-up to bfcbfd78
This commit is contained in:
parent
2a45933ff2
commit
b5c8f5f900
@ -1,3 +1,5 @@
|
|||||||
|
require_dependency "migration/base_dropper"
|
||||||
|
|
||||||
class DbHelper
|
class DbHelper
|
||||||
|
|
||||||
REMAP_SQL ||= <<~SQL
|
REMAP_SQL ||= <<~SQL
|
||||||
@ -23,7 +25,7 @@ class DbHelper
|
|||||||
text_columns = Hash.new { |h, k| h[k] = [] }
|
text_columns = Hash.new { |h, k| h[k] = [] }
|
||||||
|
|
||||||
DB.query(REMAP_SQL).each do |r|
|
DB.query(REMAP_SQL).each do |r|
|
||||||
unless triggers.include?("#{r.table_name}_#{r.column_name}_readonly")
|
unless triggers.include?(Migration::BaseDropper.readonly_trigger_name(r.table_name, r.column_name))
|
||||||
text_columns[r.table_name] << r.column_name
|
text_columns[r.table_name] << r.column_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -55,7 +57,7 @@ class DbHelper
|
|||||||
text_columns = Hash.new { |h, k| h[k] = [] }
|
text_columns = Hash.new { |h, k| h[k] = [] }
|
||||||
|
|
||||||
DB.query(REMAP_SQL).each do |r|
|
DB.query(REMAP_SQL).each do |r|
|
||||||
unless triggers.include?("#{r.table_name}_#{r.column_name}_readonly")
|
unless triggers.include?(Migration::BaseDropper.readonly_trigger_name(r.table_name, r.column_name))
|
||||||
text_columns[r.table_name] << r.column_name
|
text_columns[r.table_name] << r.column_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require_dependency 'db_helper'
|
require_dependency 'db_helper'
|
||||||
|
require_dependency 'migration/column_dropper'
|
||||||
|
|
||||||
RSpec.describe DbHelper do
|
RSpec.describe DbHelper do
|
||||||
describe '.remap' do
|
describe '.remap' do
|
||||||
@ -42,6 +43,21 @@ RSpec.describe DbHelper do
|
|||||||
|
|
||||||
expect(post.reload.cooked).to eq('test')
|
expect(post.reload.cooked).to eq('test')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not remap readonly columns" do
|
||||||
|
post = Fabricate(:post, raw: "This is a test", cooked: "This is a test")
|
||||||
|
|
||||||
|
Migration::ColumnDropper.mark_readonly("posts", "cooked")
|
||||||
|
|
||||||
|
DbHelper.remap("test", "something else")
|
||||||
|
|
||||||
|
post.reload
|
||||||
|
|
||||||
|
expect(post.raw).to eq("This is a something else")
|
||||||
|
expect(post.cooked).to eq("This is a test")
|
||||||
|
|
||||||
|
DB.exec "DROP FUNCTION #{Migration::BaseDropper.readonly_function_name("posts", "cooked")} CASCADE"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".regexp_replace" do
|
describe ".regexp_replace" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user