mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 07:33:38 +08:00
DEV: Raise an exception if trying to set a readonly column with default (#27416)
This commit is contained in:
parent
583c932173
commit
a31dc0a84a
|
@ -5,6 +5,15 @@ require "migration/base_dropper"
|
||||||
module Migration
|
module Migration
|
||||||
class ColumnDropper
|
class ColumnDropper
|
||||||
def self.mark_readonly(table_name, column_name)
|
def self.mark_readonly(table_name, column_name)
|
||||||
|
has_default = DB.query_single(<<~SQL, table_name: table_name, column_name: column_name).first
|
||||||
|
SELECT column_default IS NOT NULL
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = :table_name
|
||||||
|
AND column_name = :column_name
|
||||||
|
SQL
|
||||||
|
|
||||||
|
raise "You must drop a column's default value before marking it as readonly" if has_default
|
||||||
|
|
||||||
BaseDropper.create_readonly_function(table_name, column_name)
|
BaseDropper.create_readonly_function(table_name, column_name)
|
||||||
|
|
||||||
DB.exec <<~SQL
|
DB.exec <<~SQL
|
||||||
|
|
Loading…
Reference in New Issue
Block a user