Add state column to namespaces
Rough blueprint version:
class AddStateToNamespaces < Gitlab::Database::Migration[2.3]
  milestone '18.4'
  def change
    # rubocop:disable Migration/PreventAddingColumns -- The new state column is
    # fundamental and needs to be in the namespaces table.
    add_column :namespaces, :state, :smallint
    # rubocop:enable Migration/PreventAddingColumns
  end
end
class AddStateMetadataToNamespaceDetails < Gitlab::Database::Migration[2.3]
  milestone '18.4'
  disable_ddl_transaction!
  TABLE = :namespace_details
  COLUMN = :state_metadata
  CONSTRAINT_NAME = 'check_namespace_details_state_metadata_is_hash'
  def up
    add_column TABLE, COLUMN, :jsonb, default: {}, null: false
    add_check_constraint(TABLE, "(jsonb_typeof(#{COLUMN}) = 'object')", CONSTRAINT_NAME, validate: false)
  end
  def down
    remove_check_constraint TABLE, CONSTRAINT_NAME
    remove_column TABLE, COLUMN
  end
end
class ValidateNamespaceDetailsStateMetadataConstraint < Gitlab::Database::Migration[2.3]
  milestone '18.4'
  TABLE_NAME = :namespace_details
  CONSTRAINT_NAME = 'check_namespace_details_state_metadata_is_hash'
  def up
    validate_check_constraint(TABLE_NAME, CONSTRAINT_NAME)
  end
  def down
    # no-op
  end
end
Edited  by Rémy Coutable