DEV: Raise an exception if trying to set a readonly column with default (#27416)

This commit is contained in:
David Taylor 2024-09-02 10:09:40 +01:00 committed by GitHub
parent 583c932173
commit a31dc0a84a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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